Use this tag for questions related to JavaScript objects.

learn more… | top users | synonyms (1)

-2
votes
0answers
29 views

Should front end JavaScript classes/model objects match back end classes/models? [on hold]

When I retrieve object model properties from my backend and then build front end interface elements from that backend data, should my JavaScript class objects match my back end models for the most ...
0
votes
0answers
14 views

Sequelize Pulling data from multiple tables and passing as objects to render in EJS

am new to Node Js and associated programmes. Currently trying to create an app which uploads images with captions etc and for users to like and comment (more like instagram/facebook). So far my app ...
0
votes
2answers
20 views

Why its returning undefined ? What is the scenario?

When passing 'y' through the function argument it returns undefined but without argument it returns the valid value, But why its returning undefined when passing through argument ? var y = 'Hello ...
0
votes
0answers
17 views

What is difference between function(){} and ()=>{} [duplicate]

I am new to Javascript and was reading an article about the javascript events and found that in the article the author used '()=>{}' instead of 'function(){}' for event handlers. So i want to know ...
0
votes
1answer
16 views

JavaScript Object Literal “this” [duplicate]

I wrote a JavaScript object literal to handle multiple modals on a HTML page. When I click on a buttton to show the Modal, I'm getting the following error. Uncaught TypeError: this.showModal is not ...
1
vote
0answers
29 views

What Is the best way to access and organize instances of class objects in JavaScript?

On document.ready, let's say i loop through and I instantiate a bunch of front end Car objects based on existing div element ids. For example my divs would look something like this <div id='...
-3
votes
0answers
20 views

Javascript: ExtendObject takes in an object, property, and value as parameters [on hold]

ExtendObject takes in an object, property, and value as parameters and adds the property and value to the object. If the property already exists, overwrite its current value with the new value. Return ...
1
vote
4answers
39 views

JavaScript items missing from Object I just created

I've created an object in JavaScript and for some reason it's not saving the 17th and 20th items in the object. You can see what I mean with the below code, the 17th & 20th items are not logged ...
1
vote
3answers
351 views

IndexOf Method for Multiple Properties in Object Array

What's the best method to get the index of an object in an object array given multiple of it's properties? Imagine the following example array: var array = [ { color: 'red', ...
1
vote
1answer
19 views

How to define filters in plupload

I use plupload. Plupload allows me to select files which extensions did not defined in settings. For example I can select and upload .rar or .txt files. But I do not define these extensions in filters....
3
votes
4answers
48 views

Summarize count of occurrences in an array of objects with Array#reduce

I want to summarize an array of objects and return the number of object occurrences in another array of objects. What is the best way to do this? From this var arrayOfSongs = [ {"title":"Blue","...
3
votes
1answer
43 views

Error when using the spread operator in objects with optional property

I want to turn initial data into working data. Both have its own type, the only difference is that in the initial data, the names are optional. When I'm creating the working data, I use default value '...
2
votes
1answer
25 views

How to access a nested object with string paths? [duplicate]

I'm trying to access properties of a JavaScript object by passing a path (string or otherwise): // In a loop tableData[i].profile.firstname where 'profile.firstname' is the path. Is there a way to ...
-5
votes
1answer
26 views

When is it appropriate to create a static property instead of an instance in javascript objects?

I don't really understand how/when to use javascript prototypes. I understand the difference between these two ways of assigning properties: Static property var Date = function () {}; Date.setTime = ...
1
vote
0answers
16 views

Add bin number for accessory product onto the packing slip - Bigcommerce

I have exhausted all the resources I could think of, between their community forum and their support staff, I can't get a hint. The Scenario: A person chooses a product to buy. When they click 'add ...
1
vote
4answers
32 views

Filter array based on dynamic parameter

Say I have an array of json objects which looks like below: var codes = [{ "code_id": "1", "code_name": "code 1", , }, { "code_id": "2", ...
1
vote
1answer
55 views

How can I console.log only if result is or isn't found?

I'm creating a mini-search tool for a learning project and I can't figure out why this console.logs both times var states = { North_Dakota: {capital: 'Bismarck', region: 'Mid-west'}, Minnesota: {...
-3
votes
0answers
38 views

What does Object2 && Object1 do here? [duplicate]

Can someone explain to me what this third line does? var Object1 = [{"name":"FirstObject","last":"F"}]; var Object2 = [{"name":"SecondObject","last":"S"}]; Object2 && Object1 It returns ...
-2
votes
1answer
38 views

How to debug JavaScript code?

var myObject = { name: function() { return "Michael"; }(), age: 28, sayName: function() { alert(this.name + ":" + this.age); }(), specialFunction: function() { myObject = this; ...
0
votes
0answers
15 views

using angular drag and drop lists with angular filter groupBy and toArray

I have a list of items that I put through a number of angular filters to select them on various criteria and then finally group them by a particular property/field to create a series of lists with ...
0
votes
3answers
53 views

JSON.parse with reviver function returns undefined

I am new to JSON and getting this exception while using reviver parameter in JSON.parse(): TypeError: Cannot read property 'name' of undefined(…). Without reviver parameter code works fine but with ...
0
votes
1answer
24 views

how to edit javascript Objects with loop (Jvectormap)

I'm new to Javascript objects and Jquery and I have no clue how I do something like this: series: { regions: [{ values: { ...
-1
votes
1answer
31 views

How do I create Objects in Javascript, so I can later access their properties?

I am filling an array with objects using this code: orders.push(getOrder(orderName, sender)); ... function getOrder (orderName, sender){ this.orderName = orderName; this.orderDate = ...
2
votes
1answer
24 views

How to show code external JavaScript in alert?

How to show code external JavaScript in alert or anywhere because is value of variable s_code (function(){ var newscript = document.createElement('script'); newscript.type = 'text/...
3436
votes
18answers
1.1m views

How to remove a property from a JavaScript object?

Say I create an object as follows: var myObject = { "ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*" }; What is the best way to remove the property regex to end up with ...
6
votes
5answers
7k views

Changing an Object's Type in JavaScript

I have an array of existing object defined with JSON. The objects are obviously of the Object type. How do I associate them with a custom object type to give them specific functionality?
1
vote
2answers
6k views

optimal solution to convert json object into HTML

My HTML page primarily displays a list of pages retrieved from server. I chose to implement this is in two parts Render the page without the list of pages with spinner. After the page is loaded I ...
0
votes
2answers
55 views

how to stop the setTimeout counter from another function call through button click

I am creating an sample application, user signout time is 15 minutes. Before 2 minute, users gets an pop with warning message with countdown. There are two buttons. 1) Logout => for logout. 2) ...
24
votes
6answers
18k views

How to copy/clone a hash/object in JQuery?

I have a simple object (or hash) in Javascript: var settings = { link: 'http://example.com', photo: 'http://photos.com/me.jpg' }; I need a copy of it. Is there a settings.clone() type method ...
0
votes
1answer
28 views

Resetting a class parameter upon new instance of that class: JS ES6

I am working on creating a game that redraws the canvas every time the player goes to a new "room". While most of the functionality is there, I am having some trouble with the player... although the ...
-1
votes
0answers
32 views

How to get JSON array/object data [duplicate]

I'm stucked with javascript, i need to get this data items->NYC->labels ([November,October,September]) JSON looks like this: { "items": [ { "NYC": [ { "students": [ ...
-1
votes
1answer
28 views

Javascript Profile Lookup function

Here is what I want to achieve: *The function should check if firstName is an actual contact's firstName and the given property (prop) is a property of that contact. If both are true, then return ...
0
votes
3answers
55 views

How to check if value is a number

How to check if value is a number. If it is a number value display text center else text left. I want to know what is wrong with my statement. for (var l = 0; l < Object.keys(pods[i].data....
0
votes
1answer
28 views

Potential dangers of enabling classwide globals (Javascript)?

I have a question regarding the relative safeness of designing Javascript types that use class static/global variables. For example, suppose we had: function whatever() { if(whatever.initialized =...
2
votes
1answer
57 views

Filling in missing objects in an array using Underscore

I'm playing with a data set that counts the number of commits a person makes at a certain hour. I can create an array objects for the hour a person made a commit and how many times they committed: [ {...
0
votes
0answers
18 views

What is the correct use of namespaces is a javascript application?

I recently started a new project. And in order to improve my JavaScript skills I decided to write my code using namespaces (object based). I decided to use this pattern only because I found it ...
465
votes
28answers
359k views

Check if a value is an object in JavaScript

How do you check if a value is an Object in Javascript?
1
vote
1answer
106 views

Why are the values in my inner object blank?

I am just trying to get a JSON output like this { "SW Reqs or Problem Analysis & Estimate": { "Estimate_Days": "I", "Performers": "am", "Percent_Done": "so", "Work_Done": "...
0
votes
5answers
40 views

Javascript object get value above

I have an object like this: var structure = { "root":{ "name":"Main Level", nodes:{ "node1":{ "label":"Node 1" }, "node2":...
1
vote
0answers
14 views

Mapael update trigger

So essentially I am working with a large dataset and don't want to have to define every area for every year. But when I update to the next year it only appends the data to the map leaving the rest ...
0
votes
1answer
88 views

Javascript Object Property Undefined (GM_getValue(), GM_listValues(), Greasemonkey, Tampermonkey)

this is probably something simple, I dunno, but I am trying to create a string from an object returned by Tampermonkey (basically Greasemonkey for Chrome) GM_getValue() function. The final code looks ...
-1
votes
1answer
25 views

JavaScript constructor accesses prototype but breaks inheritance

What I want to do is to define (construct?) an object myObj that has a per-instance property id increments a property shared among all instances count puts a copy of each instance into a shared array ...
0
votes
1answer
18 views

Rendering both property value and property name of a JS object using .map()

Basically I need to render an object into a react component. It looks something like this: var obj = { prop1: "prop1", prop2: "prop2", prop3: "prop3", } I just want to print out both the ...
3
votes
2answers
81 views

Method to declare Javascript objects without the “new” keyword kosher?

I've been been learning Javascript over the past few months, and sometimes get the feeling that I'm writing code faster than I actually grasp the nuances of the language, so please bear with me here. ...
0
votes
0answers
34 views

When it is a number display text center else display text left

The numbers must center align and the text must left align Im getting a error in my code. Can anyone tell me what am I doing wrong Image Code color = color !== "" && color !== ...
1
vote
2answers
31 views

Counting length of another object property within object function — JavaScript? [duplicate]

I am new to JavaScript objects so please bear with me. This is my JavaScript: var dragSources = { elementSources: { squareSource: document.getElementById('squareSource'), circleSource: ...
0
votes
0answers
17 views

javascript dirReader iterates over entries, finds files and folders, sets booleans, but they return to false after the for loop

I have the following javascript code processEntry = function(entry){ var dirReader = entry.createReader(); var hasFolders = false; var hasFiles = false; ...
10
votes
9answers
1k views

Deep Flatten JavaScript Object Recursively

Data: var data = [ { "id": 1, "level": "1", "text": "Sammy", "type": "Item", "items": [ { "id": 11, "level": "2", "text": "...
0
votes
4answers
126 views

pushing an object onto an array from an array of objects in JavaScript

I'm trying to make a function that looks through an array of objects (first argument) and returns an array of all objects that have matching property and value pairs (second argument). Each property ...
6
votes
3answers
7k views

Removing an argument from arguments in JavaScript

I wanted to have an optional boolean parameter to a function call: function test() { if (typeof(arguments[0]) === 'boolean') { // do some stuff } // rest of function } I want the rest of ...