All Questions

535
votes
16answers
289817 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, it...
364
votes
10answers
164895 views

Dynamically access object property using variable

I'm trying to access a property of an object using a dynamic name. Is this possible? const something = { bar: "Foobar!" }; const foo = 'bar'; something.foo; // The idea is to access something.bar, ge...
226
votes
7answers
40955 views

How can I sort arrays and data in PHP?

Due to the enormous and ever repeating amount of "How do I sort my unique snowflake of an array?" questions, this is a reference collection of basic sorting methods in PHP. Please close any questio...
3974
votes
53answers
1391943 views

What is the most efficient way to deep clone an object in JavaScript?

What is the most efficient way to clone a JavaScript object? I've seen obj = eval(uneval(o)); being used, but that's non-standard and only supported by Firefox. I've done things like obj = JSON.parse(...
169
votes
8answers
152861 views

How do I print my Java object without getting "SomeType@2f92e0f4"?

I have a class defined as follows: public class Person { private String name; // constructor and getter/setter omitted } I tried to print an instance of my class: System.out.println(myPerson)...
29
votes
4answers
12698 views

How can I access an array/object?

I have the following array and when I do print_r(array_values($get_user));, I get: Array ( [0] => 10499478683521864 [1] => 07/22/1983 [2] => email@saya.com ...
1129
votes
35answers
1106422 views

Compare two dates with JavaScript

Can someone suggest a way to compare the values of two dates greater than, less than, and not in the past using JavaScript? The values will be coming from text boxes...
637
votes
10answers
490278 views

Object comparison in JavaScript

What is the best way to compare objects in JavaScript? Example: var user1 = {name : "nerd", org: "dev"}; var user2 = {name : "nerd", org: "dev"}; var eq = user1 == user2; alert(eq); // gives false ...
395
votes
44answers
306067 views

How to determine equality for two JavaScript objects?

A strict equality operator will tell you if two object types are equal. However, is there a way to tell if two objects are equal, much like the hash code value in Java? Stack Overflow question Is the...
350
votes
41answers
108002 views

javascript test for existence of nested object key

If I have 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 wa...

Previous Next