65,005 questions
7585
votes
40
answers
3.4m
views
How do I remove a property from a JavaScript object?
Given an object:
let myObject = {
"ircEvent": "PRIVMSG",
"method": "newURI",
"regex": "^http://.*"
};
How do I remove the property ...
5157
votes
67
answers
3.1m
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(...
Advice
0
votes
1
replies
74
views
Create an X word combination linked to a specific set of data
To start, here is an example:
When a messenger app wants you to share your contact information, they assign you a random 4-6 word combination (e.g. TIGER-TRUCK-FIRES-GHOST-TILES) that acts as a human ...
4136
votes
33
answers
3.8m
views
Checking if a key exists in a JavaScript object?
How do I check if a particular key exists in a JavaScript object or array?
If a key doesn't exist, and I try to access it, will it return false? Or throw an error?
3082
votes
44
answers
3.1m
views
Length of a JavaScript object
I have a JavaScript object. Is there a built-in or accepted best practice way to get the length of this object?
const myObject = new Object();
myObject["firstname"] = "Gareth";
...
3247
votes
49
answers
1.5m
views
Detecting an undefined object property
How do I check if an object property in JavaScript is undefined?
2398
votes
32
answers
1.7m
views
Iterate through object properties
var obj = {
name: "Simon",
age: "20",
clothing: {
style: "simple",
hipster: false
}
}
for(var propt in obj){
console.log(propt + ': ' + obj[propt]);
}
...
958
votes
78
answers
1.3m
views
How can I remove all duplicates from an array of objects?
I have an object that contains an array of objects.
obj = {};
obj.arr = new Array();
obj.arr.push({place: "here", name: "stuff"});
obj.arr.push({place: "there", name: &...
952
votes
63
answers
1.4m
views
Most efficient method to groupby on an array of objects
What is the most efficient way to groupby objects in an array?
For example, given this array of objects:
[
{ Phase: "Phase 1", Step: "Step 1", Task: "Task 1", Value: "5" },
{ Phase: "Phase ...
1037
votes
77
answers
990k
views
How can I 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 ...
1248
votes
42
answers
2.4m
views
Converting an object to a string
How can I convert a JavaScript object into a string?
Example:
var o = {a:1, b:2}
console.log(o)
console.log('Item: ' + o)
Output:
Object { a=1, b=2} // very nice readable output :)
Item: [object ...
2536
votes
16
answers
1.6m
views
How can I check if an object has an attribute?
How do I check if an object has some attribute? For example:
>>> a = SomeClass()
>>> a.property
Traceback (most recent call last):
File "<stdin>", line 1, in <...
1125
votes
28
answers
748k
views
How to conditionally add a member to an object?
I would like to create an object with a member added conditionally.
The simple approach is:
var a = {};
if (someCondition)
a.b = 5;
Now, I would like to write a more idiomatic code. I am trying:
...
1327
votes
21
answers
916k
views
Difference between ( for... in ) and ( for... of ) statements?
I know what is a for... in loop (it iterates over the keys), but I have heard about for... of for the first time (it iterates over values).
I am confused about for... of loop.
var arr = [3, 5, 7];
arr....
2494
votes
19
answers
1.3m
views
Calling a function of a module by using its name (a string)
How do I call a function, using a string with the function's name? For example:
import foo
func_name = "bar"
call(foo, func_name) # calls foo.bar()