39
votes
2answers
6k views

Access / process (nested) objects, arrays or JSON

I have a (nested) data structure containing objects and arrays. How can I extract the information, i.e. access a specific or multiple values (or keys)? For example: var data = { code: 42, ...
1101
votes
30answers
278k views

Most efficient way to clone an object?

What is the most efficient way to clone a JavaScript object? I've seen: obj = eval(uneval(o)); but that's not cross platform (FF only). I've done (in Mootools 1.2) things like this: obj = ...
278
votes
26answers
124k views

Most elegant way to clone a JavaScript object

I have an object x. I'd like to copy it as object y, such that changes to y do not modify x. What's the most elegant way of doing this in JavaScript? Edit: I realize that copying objects derived ...
104
votes
11answers
73k views

Object comparison in JavaScript [duplicate]

Possible Duplicate: How do you determine equality for two JavaScript objects? What is the best way to compare Objects in JavaScript? Example: var user1 = {name : "nerd", org: "dev"}; var ...
16
votes
1answer
9k views

javascript object, access variable property name?

If i have a javascript object that looks like below var columns = { left: true, center : false, right : false } and i have a function that is passed both the object, and a property name like ...
50
votes
6answers
32k views

Sorting JavaScript Object by property value

If I have a JavaScript object such as: var list = {"you": 100, "me": 75, "foo": 116, "bar": 15}; is there a way to sort the properties based on value? So that I end up with list = {"bar": 15, ...
356
votes
14answers
283k views

Why is null an object and whats the difference compared to undefined

Why is null considered an object in javascript? Is checking if ( object == null ) do something the same as if ( !object ) do something And also What is the difference between ...
120
votes
7answers
94k views

Deleting Objects in JavaScript

I'm a bit confused with JavaScript's delete operator. Take the following piece of code: var obj = { helloText: "Hello World!" }; var foo = obj; delete obj; After this piece of code has been ...
75
votes
11answers
43k views

Find object by id in array of javascript objects

I've got an array: myArray = [{'id':'73','foo':'bar'},{'id':'45','foo':'bar'},etc.] I'm unable to change the structure of the array. I'm being passed an ID#, e.g. '45', and I want to get 'bar' for ...
45
votes
11answers
29k views

Javascript isDOM — How do you check if a Javascript Object is a DOM Object?

I'm trying to get: document.createElement('div') //=> true {tagName: 'foobar something'} //=> false In my own scripts, I used to just use this since I never needed tagName as a property: ...
29
votes
11answers
5k views

javascript test for existence of nested object key

If I a reference to an object - var test = {}; that will potentially (but not immediately) have nested objects, something like - { level1:{level2:{level3:'level3'}} }; what is the best way to ...
43
votes
3answers
30k views

How to create object property from variable value in javascript?

I want to add new property to 'myObj', name it 'string1' and give it a value of 'string2', but when I do it it returns 'undefined: var myObj = new Object; var a = 'string1'; var b = 'string2'; ...
54
votes
5answers
14k views

`new function()` with lower case “f” in JavaScript

My colleague has been using "new function()" with a lower case "f" to define new objects in JavaScript. It seems to work well in all major browsers and it also seems to be fairly effective at hiding ...
39
votes
12answers
30k views

JavaScript object size

I want to know the size occupied by a JavaScript object. Take the following function - function Marks() { this.maxMarks = 100; } function Student() { this.firstName = "firstName"; ...
26
votes
10answers
34k views

Using jQuery to compare two arrays

I have two arrays of JavaScript Objects that I'd like to compare to see if they are the same. The objects may not (and most likely will not) be in the same order in each array. Each array shouldn't ...

1 2 3 4 5 21
15 30 50 per page