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(...
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
3247 votes
49 answers
1.5m views

How do I check if an object property in JavaScript is undefined?
Matt Sheppard's user avatar
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
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
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
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
2029 votes
2 answers
2.3m views

Which is the right thing to do? if (myObj['key'] == undefined) or if (myObj['key'] == null) or if (myObj['key'])
user avatar
1717 votes
6 answers
468k views

Why does the following class declaration inherit from object? class MyClass(object): ...
tjvr's user avatar
  • 18.1k
1514 votes
10 answers
1.5m views

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 I ...
spankmaster79's user avatar
1513 votes
11 answers
2.6m views

How do I refer to the null object in Python?
Lizard's user avatar
  • 45.4k
1391 votes
23 answers
1.8m views

If I defined an object in JS with: var j={"name":"binchen"}; How can I convert the object to JSON? The output string should be: '{"name":"binchen"}'
Bin Chen's user avatar
  • 63.6k
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
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

15 30 50 per page
1
2 3 4 5
4334