Use this tag for questions related to JavaScript objects.

learn more… | top users | synonyms (1)

0
votes
1answer
34 views

Pushing data into object clears the other values

I'm making trying to push data into an object, but as soon as I push data to userID.name, the value of userID.age gets reset(?) in the console. Here's my code: if (input.indexOf("ben") >= 0){ ...
2
votes
3answers
26 views

Iterate over object and input each property into a function

I have this node.js object. DataObj = { ID: { data: '1' }, IS_PRESENT: { data: '1' }, DATA_TYPE: { data: '1' } } ; I have a function which can take each property of DataObj as an ...
1
vote
1answer
31 views

Comparing two objects with undefined values using underscore.js

Using underscore.js I am trying to compare two objects against each other and if they are they same I want to return true. To accomplish this I am using _.isEqual(). var a = {0: "2", 1: "11", 2: "1"}...
-1
votes
0answers
34 views

Does removeProperty function on objects works for all test cases? - Javascript [duplicate]

Implement the removeProperty function that takes an object and a property name and does the following: If object obj has property prop, it removes the property from the object. If the property has ...
-3
votes
0answers
43 views

How to fix javascript's undefined and map function error? [on hold]

I've a function named enter code here selectTargetingLibrary(targetingLibrary) { console.log("targetingLibrary = ",targetingLibrary); this.data.selectedTargetingLibrary = ...
2
votes
3answers
47 views

Rendering JavaScript Object in React

I have a React project set up to fetch an Object from a Firebase database and render this to my page. However I do not know how to render the data properly. The data I am fetching looks like this: { ...
-1
votes
0answers
31 views

Which structure of JS coding is best

I want to know which way of JS coding is best. I have two different kind of JS code structure. They are, Type : 1 // 1. Json Structure appLoading.js // First loading file var com =...
12
votes
4answers
731 views

How to find differences between two JavaScript arrays of objects?

I have two JavaScript arrays orig (the original array of objects) and update (the updated orig array of objects) that have the same length and contain objects, and I want to output the differences ...
0
votes
3answers
40 views

Javascript date in specific format from string

How can I obtain a javascript Date in ddmmyyyy format without changing Date object to String object? I have a String stringDate = 31/08/2015 (in dd/mm/yyyy format) I want to obtain a javascript Date ...
-1
votes
1answer
41 views

Dynamically add object in javascript array

I have json: var obj = '{"Form":[],"Provider":[]}'; I push the data with variable value to make dynamic objects: var pName = 'Tester'; var data = { pName :["testing"] }; console.log(obj['...
0
votes
1answer
32 views

es6 Class Inheritance

I am trying to merge statics and prototypes of several classes in to 1 masterclass like in the example below. Is that actually possible? My goal is that im able to merge the statics and prototypes to ...
1
vote
2answers
39 views

Define JavaScript object literal so that the properties exists for all objects in an array?

I define a JavaScript object literal with defaults so that my template can access them later: self.emails = [{ address: "", validation: { warning: false, message: "", } }];...
2
votes
1answer
38 views

Chapter 7, eloquent JavaScript: LifelikeWorld

I've been reading this book, and, with a lot of hardship and other resources, made it through here (it alone was too hard but it is still quiet useful, along with other resources). This is the code I ...
0
votes
0answers
8 views

Sorting javascript object by value

I have java script object as the following: Object {24: "Garthj - Jims Carpet Cleaning - Cronulla", 25: "Michaelc - ", 26: "Arielqld - Tile Stone & Concrete Care", 27: "Zolik - Kisses Clean Pty ...
-2
votes
2answers
35 views

Merge two objects

I have 2 two level JavaScript structures, which I need to merge. What would be the easiest way? var object1={ "section1": { "prop1": 0, "prop2": 0 }, "section2": { "something": 0, ...
-1
votes
2answers
24 views

Calling object literal function with this returning TypeError

I am having a scoping issue. I have a simply object literal function, with a number of methods. I am trying to call method4(), from method1() var myObjectFunc = function() { return { method1: ...
1
vote
1answer
28 views

Global object returns original value even thou its been replaced

On initial page load, I create a global object. Then set its value with a function. function set_globals(table){ // Setup Local Storage setLocalStorage(); // DEBUGGING debug = AC....
0
votes
1answer
22 views

What would cause pdfMake to ignore this definition?

We are using the pdfMake javascript framework to render HTML to a PDF document. pdfMake.org Given that a simple working document definition object is rendered thusly: var docDefinition = { ...
2
votes
2answers
28 views

Using jQuery grep on an object

I have an object which looks like that: const myObject = { 3723723: null ,3434355: true ,9202002: null } Using jQuery grep method I need to get the count of the array where the value is not ...
0
votes
2answers
21 views

Create automatic javascript queue with time out to shift items

What I'm trying to achieve is very straight forward but I'm confused. I'm trying to make a queue that holds hospital patients, they will be logged in the system, added to an array (FIFO) and then ...
2
votes
3answers
54 views

Find whether Value in Object exists within an array

I am trying to find whether the value roomTypeFilter exists within an Object inside an array. I then want to perform conditional statements depending whether the value roomTypeFilter exists or not. ...
-4
votes
3answers
56 views

How to merge two different array of objects using javascript

I have two different array of objects.And i have to merge the two array of objects in nested way. var array1=[{ PersonalID: '11', qusetionNumber: '1', value: 'Something' }, { ...
-1
votes
3answers
45 views

Cannot read property 'concat' of undefined

to begin with, I have a multilevel of entities as in country unit ----> customer reporting group ----> customers each country unit has different customer reporting groups and each of the later has ...
1
vote
2answers
36 views

Create an object from another object's group by key using lodash

For the given structure: [{ file: [{ en: 'asset_string_en.jpg' }, { ch: 'assets_string_ch.jpg' }], assetName: 'assetName1' }, { file: [{ en: '...
1
vote
4answers
49 views

Converting an array of strings into an array of objects

I have an array of strings: ["14: London", "15: Manchester", "16: Bristol"] I need to change it into an array of objects that would look like this: [{14: "London"}, {15: "Manchester"}, {16: "...
-3
votes
1answer
43 views

How to sort JavaScript object by value? [duplicate]

My object like as below: var list = { 10: "Z", 9: "Y", 11: "X"}; Output should be as below (in form of alphanumeric sort using value): var New_list = { 11: "X", 9: "Y", 10: "Z"};
2
votes
1answer
27 views

Class object in one array gets changed when I create a class object of something else

To keep it short and let the example speak for itself. I create a object and print it out (it's OK), I create more objects (of the same type) and print out the first object again, now it shows the ...
0
votes
3answers
42 views

Why e is not used in Javascript methods called from onclick?

As far as I know "e" represent "event" in Javascript methods, but I do not understand what if I want to use some properties as mentioned below in the Javascript methods when I call them. For example ...
1
vote
3answers
27 views

How would I loop over a group of JS objects and print a statement for each? [duplicate]

var teams = [ { city: 'Vancouver', nickname: 'Canucks', league: 'NHL' }, { city: ...
-2
votes
2answers
26 views

Finding a key in an object by using values from an array

I have an array which is dynamically created by selecting items from a list: [2, 4] I also have an array of objects: [{id: 1, name: "Param1"}, {id: 2, name: "Param2"}, {id: 3, name: "Param3"}, {id:...
0
votes
0answers
21 views

javascript, The different between using `new` and without [duplicate]

Assuming i have this code: function f(x){ this.d = $("<div>").html(x).show(); } And these calls: f("1"); // call 1 x = new f("2"); // call 2 what is the difference between the ...
0
votes
0answers
12 views

Immutable.js: Inherit from Immutable.List and adding custom functions

I'm using plain old JavaScript (no ES6 or TypeScript). I want to create a special type of Immutable.List, that should have an additional method. Something like this: // PSEUDO CODE class MyList ...
0
votes
2answers
38 views

Map 2 arrays based on key

I have an array with some dates and values. Eg: In date x we have 20 orders, in date y we have 32 orders. [2016-08-09: 38, 2016-08-08: 75, 2016-08-05: 13, 2016-08-04: 23, 2016-08-03: 10] The second ...
-4
votes
1answer
40 views

sorting objects in javascript

Sort the below dictionary/ array key using Javascript and output the information in key:value format on a Polymer interface. The entire numeric key should be sorted in an ascending order and all the ...
3
votes
1answer
60 views

How to read object properly in JavaScript

I am new to programming and recently began learning Javascript, I have a problem that appeared in few exercises that I made. I searched the site for more information but have not found a solution for ...
2
votes
3answers
22 views

what is the benefit of using prototype after creating constructor function?

If you have a constructor function like var SomeClass = function(){ this.a= ""; this.b= ""; } then let's say you add another method using prototype SomeClass.prototype.fn = function fn(){ ...
0
votes
1answer
21 views

Javascript copy and pasting doesn't format model value correctly

Hi I am making an SSN formatter here is my code element.keyup(function(event) { var inputField = event.target; var val = inputField.value.replace(/[^0-9]/g,...
0
votes
2answers
35 views

Moving (not copying) property inside object - using reference

How do I move an array element, to another location in the tree? Assuming: obj = [ { x : [{/*obj*/},{/*obj*/}] }, { x : [{/*obj*/},{/*obj*/}] }, { x : [ {/*obj*/}, ...
-1
votes
1answer
38 views

Stop jquery iteration if the .search method will be equal to -1

I built a nice tools in order to find my store on a google maps which iterate every location from a javascript object. I need a "no search result" when my .search function won't find any result. The ...
-1
votes
0answers
24 views

how to solve Undefined index: cannot set property 'value' of null error?

I have three dialogs which will be opened by clicking button... In this dialog i am populating checkboxes from jQuery code i added at last.. Now When i submit the form, It gives me error saying that ...
3
votes
2answers
40 views

Proxy object cannot be added to DOM (traps doesn't trigger either)

I am trying to make a Proxy object of Image to trap properties but even with an empty handler I get an error message. TypeError: Argument 1 of Node.appendChild does not implement interface Node. ...
0
votes
0answers
24 views

Access properties within closure [duplicate]

I am trying to encapsulate all the properties of an object and the necessary functions within the object itself so other functions can't access them. The problem is that inside my Object....
1
vote
2answers
49 views

Why have multiple object methods without parameters?

I had recently begun learning and implementing objects in JavaScript. But it made me think, if the functionality of an object can be put into one method, then why use multiple methods like Example....
-1
votes
0answers
10 views

How can I resize me once merotate an object on the canvas

How can I resize once I rotate an object on the canvas. For example, I want to create a triangle object that can rotate to reverse and minimize exaggerated like that on this site https://tees.co.id/...
0
votes
1answer
37 views

Defining Javascript's object property by invoking function

Suppose I have a javascript Object and I want to define a property and property attributes for it. i.e I want to define scaleRatio through a function. How would I go about this ? I know I can do ...
-3
votes
1answer
49 views

cannot read property of undefined

Here's my code: function makeIframePlayer(newTracks){ var iframe = document.querySelector("iframe"); var iframeSrc="https://embed.spotify.com/?uri=spotify:trackset:PREFEREDTITLE:"; var ...
5
votes
3answers
81 views

Create object from forEach

I'm trying to figure out if there's a way to rewrite this code as a single object creation: my_array = [ {key: 1, value: "foo"}, {key: 2, value: "bar"} ]; let my_obj = {}; my_array.forEach((elem)...
0
votes
1answer
26 views

How to address an unknown field in a json structure?

I would like to address an unknown field in my json structure, which is like below. I would like to address the gateways in that structure, I have reached till semt.gateways where I got those field ...
0
votes
1answer
39 views

Reference to Object is lost somehow

I'm building a fairly advanced app using the Aurelia framework that uses models, services and custom elements. I have a user model containing username, email etc as well as a bool isLoggedIn. I have ...
10
votes
1answer
178 views

Anonymous class instance -— is it a bad idea?

In ES6 we can do anonymous class: var entity = class { } But we can also instantiate it: var entity = new class { constructor(name) { this.name = name; } getName() { return this.name; } }('...