Use this tag for questions related to JavaScript objects.

learn more… | top users | synonyms (1)

1
vote
1answer
20 views

Redux Deep Copying Arrays Even if They Remain Unchanged?

If my state looks like this: const initialState = { color: 'blue', sizes: ['S', 'M', 'L'], } And I want to change the color, my reducer should return this right: return { ...state, color: ...
2
votes
0answers
23 views

How to refer JS files like componenet and use acrsoss the web application

I have one image editor and it has lot of JS files. asp.net empty project containing all JS files that required for that editor. Now, I want to keep these all JS at some common place and refer to ...
0
votes
4answers
55 views

Normalise array of objects & key by id

I'm looking to normalise some data returned from an API. Already using underscore within the project. var res = [{ badge_no: 123, id: 1, name: 'bob' }, { badge_no: 456, id: 2, ...
1
vote
2answers
36 views

How to clone new group of fields with and increment the name attribute

I have problem when i'm trying to copy a group of fields. for example I have <div class="must_Duplicated "> <div class="form-group"> <label >Name:</label> <input ...
0
votes
1answer
26 views

Typescript: what could be causing this error? “Element implicitly has an 'any' type because type 'Object' has no index signature”

i'm trying to get an array of all the keys in an object with nested properties, my code: public static getKeys(obj: Object) { let keys: string[] = []; for (let k in obj) { if (typeof ...
0
votes
1answer
27 views
280
votes
18answers
374k views

How to get all properties values of a Javascript Object (without knowing the keys)?

If there is an Javascript object: var objects={...}; Suppose, it has more than 50 properties, without knowing the property names (that's without knowing the 'keys') how to get each property value ...
-1
votes
2answers
32 views

JavaScript Functions as Objects

I had a question regarding JavaScript Functions. I read Functions as Objects where we can add properties and methods to the functions as well but I notice some strange behavior when I log out the ...
0
votes
2answers
60 views

Update values inside javascript object

I am working with the Affirm javascript API and I need to be able to update the values inside the checkout object but am having trouble doing so. I have tried what is mentioned here but it isnt ...
0
votes
2answers
40 views

Passing JavaScript object from velocity template to Java

I am trying to pass a Java Script object form my .vm file to my Java class. var createReqFields = {BookName:"Effective Java",Author:"Joshua Bloch"}; I am able to see the values in my variable ...
0
votes
3answers
30 views

Javascript Object Property Inheritence

My goal with my method is to inherit the property name 'c' and append it to obj1. Not sure what I am missing here, instead of 'c' my meth inherits the name 'key2'. var obj1 = { a: 1, b: 2 ...
0
votes
1answer
21 views

Javascript: Weird error when working with JS Objects

So I've been encountering this error quite a bit lately and it looks like this... Main.js:84 Uncaught TypeError: Cannot set property 'CurrParent' of undefined And basically I have a couple ...
1
vote
2answers
34 views

In Typescript, is it possible to make a property name of a Javascript Object accept multiple values?

for example, if i create a new Object type: interface NEWOBJECT { name: {}; } would it be possible to make it so that name can be either name1 or name2, so that i can create NEWOBJECT's with ...
30
votes
4answers
14k views

JavaScript, elegant way to check nested object properties for NULL/undefined [duplicate]

a "problem" which i have every now and then is that i have an object e.g. user = {} and through the course of using the app this gets populated. Let's say somwhere, after an AJAX call or something i ...
-16
votes
0answers
93 views

Write a function that takes 2 colors as arguments and returns the average color. -JavaScript [on hold]

The parameters will be two 6-digit hexadecimal strings. This does not need to be validated. The return value should be a 6-digit hexadecimal string. The hexadecimal strings represent colors in RGB, ...
1
vote
2answers
31 views

How to add a property from another object if it doesn't exist in the first object in JavaScript

I have two objects, obj1 and obj2. If obj2 has a key that obj1 doesn't have, that obj2 key/value pair gets added to obj1. for example: obj1 = { a:1, b:2 } obj2 = { b:4, c:3 } c:3 ...
3
votes
4answers
756 views

Understanding the superior method introduced by Crockford

In the functional inheritance pattern, Crockford introduces a new superior method via: Object.method('superior', function (name) { var that = this, method = that[name]; return function ()...
900
votes
25answers
952k views

How can I display a JavaScript object?

How do I display the content of a JavaScript object in a string format like when we alert a variable? The same formatted way I want to display an object.
52
votes
3answers
62k views

Using curl POST with variables defined in bash script functions

When I echo I get this, which runs when I enter it into the terminal curl -i \ -H "Accept: application/json" \ -H "Content-Type:application/json" \ -X POST --data '{"account":{"email":"akdgdtk@test....
0
votes
2answers
33 views

What is the difference between Object.assign and JSON.parse(JSON.stringify(obj)) for deep cloning of an object?

I want to know is there a difference between Object.assign({}, obj) and JSON.parse(JSON.stringify(obj)) for deep cloning of an object? Can anyone explain if they have any idea?
0
votes
3answers
37 views

How to create a variable that exists only in an object state?

The title of the question may not be the best but here's the code I've written so far: var menuState = { //state variables menuBttn: { x: _canvas.width/2, y:_canvas.height/2,...
0
votes
0answers
48 views

Why can't update access an objects img properties?

I'm trying to create a simple JS game engine on my own. Here's the code for one of the states. var menuState = { //state variables menuBttn: {x: _canvas.width/2, y:_canvas.height/2, img: ...
15
votes
5answers
16k views

Efficiently rename/re-map javascript/json object keys within array of objects

I have some structured JSON data like so. Let's assume this is interchangeable, via JSON.parse(): [ { "title": "pineapple", "uid": "ab982d34c98f" }, { "title": "...
0
votes
3answers
42 views

JavaScript Object Structure Issue

I am having an issue traversing the objects returned from uploaded file data, but it appears that potentially the object structure that is being returned is preventing me from capturing specific ...
0
votes
1answer
65 views

Can I get one symbol from string after clicking?

I have DOM document with text content like as: <p>Content scripts aren't completely cut off from their parent extensions. A content script can exchange messages with its parent extension</p&...
491
votes
30answers
375k views
0
votes
2answers
39 views

JavaScript: Deep check objects have same keys

Question is similar to: How can I check that two objects have the same set of property names? but only one difference I want to check: var objOne = {"a":"one","b":"two","c":{"f":"three_one"}}; var ...
0
votes
0answers
9 views

how to creat a javascript webapp for visually chalanged

I have to load a page with following features. Preload with an mp3 file and playing while loading, its arount 30 seconds. Automatically get focus to the edit box and waiting for the input. ...
-1
votes
1answer
33 views

Regular expression to escape inner double quotes in json

I have an issue, I was wondering if somebody could help me with a regular expresion to replace this: {"name": "Raul "the cat" Gonzalez"} To this: {"name": "Raul \"the cat\" Gonzalez"} In order to ...
26
votes
4answers
15k views

using reserved words as property names, revisited

Can a reserved word be used as an object's property name? This issue was raised in indirectly previous a stackoverflow question. the answer seemed general consensus by @Squeegy: You can use those ...
1
vote
2answers
46 views

Get index of array's object item by property and value

I'm having troubles with updating found object. I also tried Find object by id in an array of JavaScript objects and Get JavaScript object from array of objects by value or property Please help. ...
1
vote
4answers
172 views

What's the difference between a regular push and an Array.prototype.push.apply

I don't quite understand the difference between the following 2 lines of code. In my code, the line with "apply" works the way I want it to, and the line with just regular push doesn't. So what is ...
0
votes
4answers
57 views

javascript - how to get an object to return a value that is not the object itself

When creating a x = new Date() object, if you put it into console.log(x) a string will be output. Is there a way to make a custom object that will return a different value that is not an object ...
-2
votes
4answers
75 views

How do you put the last character 1st in a string [closed]

The R is displaying last in the string initially it must display first how can I put the last character before the number value in the string so that it can display at the beginning of the value ...
0
votes
2answers
60 views

find sum of Boolean values JavaScript object array

Hi i am trying to find the sum of Boolean values in the object array in JavaScript My json like be var myoBj = [{ "id": 1, "day": 1, "status": true }, { "id": 2, "day": 1, "status": ...
2
votes
5answers
540 views

Why can't I set a JavaScript function's name property?

I am learning JavaScript and read that functions are like objects and can have properties set like this: var person = function(){ } person.name="John Smith"; //output "" person.age=21; //output 21 ...
-2
votes
5answers
32 views

Benefit of using bracket notation (with variables) to access a property of an object

While utilizing alternatives such as the dot operator make sense when needing to access some stored information, I'm having a little bit of difficulty understanding why and in what scenarios we would ...
0
votes
1answer
72 views

ImmutableJS: merge two list of objects, without duplicating them

Supposing I have the below: var allFoods = Immutable.List(); var frenchFood = Immutable.List([ { 'type': 'french fries', 'price': 3 }, { 'type': 'petit gateau', 'price': 40 }, {...
0
votes
1answer
47 views

Javascript object property gets updated on assignment [duplicate]

I have created a JavaScript object like below - var objtvar = {defaultPoints: [[0,0],[0,-10],[2.5, -10], [2.5, -10],[5, -10],[5,0]]} I need to assign the defaultPoints property to another array and ...
0
votes
1answer
44 views

Different JS Namespace declarations

I wonder, are the following code example the same? Version 1: var myNamespace = {}; myNamespace.say = function() {...} Version 2 (JS-Fiddle: https://jsfiddle.net/542wbkat/) : var myNamespace = new ...
0
votes
3answers
40 views

Using variables as keys in Object supplied to Object.assign

I am using Object.assign to get a new copy of an Object with added properties from another map. This is usually as simple as Object.assign(existingObject, {"new_key", "new_value"}), but when "new_key" ...
0
votes
0answers
36 views

Illustrator CS6 tracingoptions maxColors not working?

I am using extendscript to create a script for CS6. I have reffered to the PDF here: http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/pdf/illustrator/scripting/cs6/Illustrator-Scripting-...
0
votes
0answers
19 views

Window.closed function works even before closing the window

I am opening a window from a page ( parent), using the openPopup() function. when the child window closes, I need some activity in the parent window. Some of the IE browsers, this is not functioning ...
1
vote
1answer
27 views

Accessing 'this' inside an independent function in a Constructor

I have a Dog Constructor as follows: var Dog = function(name,type) { this.name = name; this.type = type; this.normalObjFunc = function() { this.name = "kl"; } var retfunc = ...
0
votes
3answers
39 views

React component DOM not updating

I have an array of objects. Each object represents a product and they are added and removed from this array and the DOM reflects this properly. Problem is when I update one of the properties of these ...
2
votes
1answer
37 views

JavaScript Prototype Object.create

I have two version code let Animal = function() { } Animal.prototype.voice = "Miau" let Cat = function() { } Cat.prototype = Object.create(Animal.prototype); ...
0
votes
1answer
23 views

Ionic2 private property in a class always empty even if set in that class

I'm new with Ionic2, and TypeScript and try to play with Classes, properties, getters and setters. My first class just initialize some datas in a webSQL database and expose methods that retrieve infos,...
11
votes
8answers
20k views

jQuery create object from form fields

How can I create a object with a form's fields and values? like this one: { fields: { name: 'foo', email: '[email protected]', comment: 'wqeqwtwqtqwtqwet' } } assuming the ...
-3
votes
2answers
40 views

Returning an object from a function in JavaScript

I have a function that returns an object in javascript. The objects returned are instances of a "messagePack" that I want to send to the server. Each messagePack will be different. E.g.: function ...
4
votes
4answers
65 views

Trying to understand scoping within two short JavaScript functions

What is the difference between the following two JavaScript functions? I know variables declared with var are local inside the function, and if declared withthis` keyword are exposed to outer word. is ...