Skip to main content
7585 votes
40 answers
3.4m views

Given an object: let myObject = { "ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*" }; How do I remove the property ...
johnstok's user avatar
  • 98.6k
5157 votes
67 answers
3.1m views

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

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 ...
jakeprime's user avatar
4136 votes
33 answers
3.8m views

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?
Adam Ernst's user avatar
  • 54.3k
3082 votes
44 answers
3.1m views

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"; ...
Gareth Simpson's user avatar
3247 votes
49 answers
1.5m views

How do I check if an object property in JavaScript is undefined?
Matt Sheppard's user avatar
2398 votes
32 answers
1.7m views

var obj = { name: "Simon", age: "20", clothing: { style: "simple", hipster: false } } for(var propt in obj){ console.log(propt + ': ' + obj[propt]); } ...
Rafay's user avatar
  • 24.4k
958 votes
78 answers
1.3m views

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: &...
Travis's user avatar
  • 11k
952 votes
63 answers
1.4m views

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 ...
D'Arcy Rail-Ip's user avatar
1037 votes
77 answers
990k views

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 ...
user avatar
1248 votes
42 answers
2.4m views

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 ...
user680174's user avatar
  • 12.5k
2536 votes
16 answers
1.6m views

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 <...
Lucas Gabriel Sánchez's user avatar
1125 votes
28 answers
748k views

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: ...
viebel's user avatar
  • 20.9k
1327 votes
21 answers
916k views

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....
Mukund Kumar's user avatar
  • 23.6k
2494 votes
19 answers
1.3m views

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()
ricree's user avatar
  • 37k

15 30 50 per page
1
2 3 4 5
4334