Use this tag for questions related to JavaScript objects.

learn more… | top users | synonyms (1)

-5
votes
0answers
16 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
48 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
20 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
34 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
36 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
23 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 ...
-4
votes
0answers
23 views

html code for creating a popop box by selecting a item in menu bar [closed]

I need to write a html file and java script so that I can open a popopwindow by selecting one item from a menu bar, and that popopwindow should contain a form such as login page and a submit button
3
votes
2answers
38 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
22 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
43 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
79 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
25 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
38 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 ...
9
votes
1answer
160 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; } }('...
0
votes
0answers
16 views

Why can you not bind a click event handler inside an if statement?

So, I had this strange error show up on a TicTacToe game I was coding, where if I bound a click event handler inside of an if statement, I just ended up getting junk values. Is there documentation ...
0
votes
2answers
37 views

Make a new array of objects without repeating key value pairs

Lets say I have an array of objects: var myData = [ {"ccode":"AFG", "cname":"Afghanistan", "figure":"1", "year":"2012"}, {"ccode":"AFG", "cname":"Afghanistan", "figure":"3", "year":"2013"}, {"...
-1
votes
0answers
26 views

JavaScript do while loop wtih multiple parameters

I have this do while look in JavaScript: var dscr2 = 0.0; var yield_on_debt = 0.0; var interestCover = 0.0; do { loanAmount = loanAmount - 5000; $scope.QuickQuoteData.LTV = loanAmount / ...
-6
votes
1answer
48 views

Convert JSON object containing objects into an array of objects

My data is currently stored in this format, stored in a JSON file: { "name": { "0": ______, "1": ______, "2": ______ }, "xcoord": { "0": ______, "1"...
-2
votes
2answers
43 views

When object property is not defined then console.log(obj.property) gives “undefined”, why?

Lets say we have, var obj = { name: "AKS" }; console.log(obj.name); console.log(obj.lname); Output: AKS undefined Where else if we do: var ...
-2
votes
2answers
23 views

Errors nesting objects javascript

So I seem to be having trouble creating inner nested objects in JS and calling them. I have been looking at various examples but this has been a persisting problem and I would like a bit of ...
-1
votes
1answer
50 views

Why can I not iterate over this object? [duplicate]

I am trying to iterate over an object, but the jquery $.each won't fire. This is the outcome of the $fileNames variable: and this is the code I've built so far: $("input[type=button]").on("click", ...
2
votes
1answer
50 views

Object.create vs new

The following code works when I create my object with the constructor but when I do object.Create it doesn't get initialized properly. functionName is not a function. I have two questions. Why isn't ...
0
votes
1answer
39 views

How to set a function's prototype

I am trying to understand Javascript's prototype. I know I can add functions to prototype individually Calculator.prototype.calculate = function(){};, however when I tried setting a new prototype ...
1
vote
1answer
23 views

Trouble with method that takes in a function and its arguments

I am having trouble passing a kata. I believe I am on the right track, but do not fully understand how to retrieve the desired results. The Instructions Write a method that takes in a function ...
0
votes
5answers
30 views

Javascript code to count occurrences of combination of elements of two different variables within object

I have a data that looks of the format [ {name: "a", class: "AA"}, {name: "b", class: "BB"}, {name: "xx", class: "XY"}, {name: "a", class: "AA"}, {name: "b", class: "BB"} ]; I ...
0
votes
3answers
26 views

How to remove an array element using a specific value

Suppose I have an array structured like this: { q1: true, q2: false, q3: false, q4: true, q5:true } Is there a way to remove all the elements that has "false" for a value in AngularJS? I tried ...
1
vote
2answers
16 views

How to get nested objects in javascript by an string as a bracket notation?

I want a method in javascript that gets a string as its arguments and return a value from a nested object like as: var obj = { place: { cuntry: 'Iran', city: 'Tehran', block: 68,...
0
votes
4answers
39 views

How can I remove the parent keys from a javascript Object?

I currently have this Object: schoolsObject = [{ "college_1": { "id":"college_1", "location":"Victoria", "name":"College One" }, "college_2": { "id":"college_2"...
0
votes
3answers
34 views

jQuery Ajax object dot notation undefined from REST

Hey guys I am having a really big problem understanding why my for each is unable to parse my REStful end point within my AJAX success function: So I have the following code: $.ajax({ dataType: "...
-2
votes
0answers
10 views

Performing parallel tasks in object of array of objects

I am new to async programming in node.js. I have an array of objects on which I have to perform some async operations on each object of the array. Functions to be performed on objects of array are ...
0
votes
2answers
33 views

javascript getting fields from an array with objects

I filled up an array with some objects like this and printing it out with JSON.stringifty(obj, null, '\t'); gives me output like this: [ { "title": "here's the title" }, { ...
-3
votes
1answer
38 views

Overriding ++ operator in JavaScript [duplicate]

I can add method addOneDay() to Date objects in order to increase Date for one day like: Date.prototype.addOneDay=function() { return new Date(this.getFullYear(),this.getMonth(),this.getDate()+1); }...
0
votes
1answer
46 views

Javascript push object as clone

I use d3 for a interactive network application. The data I need to bind changes during the interaction and consists of some selected objects from my JSON variable. For that I used map on the JSON ...
2
votes
1answer
28 views

Customize label in scatter graph in echarts by baidu

Referring this example to create scatter graph using echarts library: Basic Scattergraph My code for this is as follows: option ={ xAxis : [ { ...
0
votes
2answers
36 views

How do I check if an array includes an object with the same field in Javascript?

What is the best method to handle this? consider i'm handling a sign-up list database and i want to know whether a user the same username already exists or not? something like this: for (var i = 0; ...
1
vote
1answer
29 views

Manipulate object so that its own properties populate arrays inside the object itself

I have an array of objects like this: var array = [{ code : "1", name : "code1", parentCode : "0", children : [] },{ code : "0", name : "code0", parentCode : "#", children : [] }] How can I push to ...
0
votes
2answers
26 views

(duplicate?) When pass an object to function in JavaScript [duplicate]

var obj = { hi : 'hello' }; function myFunction( arg ) { console.log( arg.hi ); } myFunction( obj ); if I call myFunction, does javascript engine pass obj as reference? or copy? Also then, ...
-1
votes
4answers
50 views

Remove empty Objects from Array

I have a JavaScript-array with objects filled in and want to remove every object with no data. It might look like this: var myArray = [ {id: "28b", text:"Phill"}, {id: "12c", text:"...
0
votes
2answers
24 views

Trying to apply a filter to a nested array full of objects

I have a resources array which is full of objects. Each object has categories array full of objects. I am trying to apply a filter to only return resources that have category objects of a specific ...
2
votes
0answers
37 views

Is it worth to delete object properties when the object itself is not needed?

Let's say I have the following code: function foo(myobj, otherobj){ var obj = {}; obj.first = myobj; // a really big object obj.second = otherobj; // another big object // some work ...
0
votes
0answers
39 views

JavaScript Object notation type confusion [duplicate]

I am somehow confused about JS object notations. What I know is: There are 2 types of object notations. var myObj = new Object(); // Object constructor notation var myObj = {...} // Object literal ...
-1
votes
1answer
34 views

Javascript resize swf file to fit with a small div and auto play without clicking

I am trying to put a swf file in a small div of my page,the div width is 431px and height is 169px. A link for the swf is from "http://www.cp399.com/Public/swf/shipin_pk10/bjpk10.swf" and I need it ...
0
votes
1answer
45 views

Print Json as an HTML String with Angular

I am attempting to simply print single JSON objects as HTML strings. I am doing this in a twig template; so I have changed Angulars default output to {[{}]}. I am seeing all of the JSON when I view ...
0
votes
1answer
52 views

Populate a Object with random Objects, and setting specific properties in javascript

I am using NodeJS and socket.io to create an Online Browser Card Game. I have written the code at the bottom, in which an Object gets populated with two Players (0 and 1), each of those then gets an ...
0
votes
3answers
45 views

Alternative for remove() when using strict mode, filter using one element and hiding all other [duplicate]

I am trying to remove all the items from a list except "Red" on a specific condition by using remove(), but when I debug, it gives error: "Accessing the 'arguments' property of a function is not ...
0
votes
0answers
13 views

Which method to use when asking whether object's property is defined in JavaScript? [duplicate]

Learning JavaScript I ran across two methods to find out whether object has defined property. Method A if ('propertyName' in object) { } Method B if (object.propertyName) { } Using console.log() I ...