All Questions
Tagged with object properties
1,192
questions
7516
votes
39
answers
3.3m
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 ...
1028
votes
46
answers
1.5m
views
Sorting object property by values
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 = {
"...
977
votes
21
answers
662k
views
Accessing an object property with a dynamically-computed name
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, ...
877
votes
64
answers
413k
views
Test for existence of nested JavaScript 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 way to ...
454
votes
9
answers
506k
views
How to create an object property from a variable value in JavaScript? [duplicate]
I want to add a 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';
...
441
votes
12
answers
440k
views
Remove array element based on object property
I have an array of objects like so:
var myArray = [
{field: 'id', operator: 'eq', value: id},
{field: 'cStatus', operator: 'eq', value: cStatus},
{field: 'money', operator: 'eq', value: ...
331
votes
6
answers
387k
views
Is there a “not in” operator in JavaScript for checking object properties?
Is there any sort of "not in" operator in JavaScript to check if a property does not exist in an object? I couldn’t find anything about this around Google or Stack Overflow. Here’s a small snippet of ...
213
votes
13
answers
486k
views
Getting the object's property name [duplicate]
I was wondering if there was any way in JavaScript to loop through an object like so.
for(var i in myObject) {
// ...
}
But get the name of each property like this.
for(var i in myObject) {
...
160
votes
5
answers
157k
views
How to access property of anonymous type in C#?
I have this:
List<object> nodes = new List<object>();
nodes.Add(
new {
Checked = false,
depth = 1,
id = "div_" + d.Id
});
... and I'm wondering if I can ...
135
votes
11
answers
28k
views
Is it possible to get the non-enumerable inherited property names of an object?
In JavaScript we have a few ways of getting the properties of an object, depending on what we want to get.
1) Object.keys(), which returns all own, enumerable properties of an object, an ECMA5 ...
130
votes
7
answers
456k
views
How to set a Javascript object values dynamically?
It's difficult to explain the case by words, let me give an example:
var myObj = {
'name': 'Umut',
'age' : 34
};
var prop = 'name';
var value = 'Onur';
myObj[name] = value; // This does not ...
129
votes
8
answers
245k
views
How do I access properties of a javascript object if I don't know the names?
Say you have a javascript object like this:
var data = { foo: 'bar', baz: 'quux' };
You can access the properties by the property name:
var foo = data.foo;
var baz = data["baz"];
But is it ...
129
votes
2
answers
25k
views
Is it safe to delete an object property while iterating over them?
When iterating over an object's properties, is it safe to delete them while in a for-in loop?
For example:
for (var key in obj) {
if (!obj.hasOwnProperty(key)) continue;
if (shouldDelete(...
128
votes
20
answers
98k
views
Access JavaScript property case-insensitively?
Assume I have an object:
var obj = {
foo:"bar",
fizz:"buzz"
};
I need to access a property of that object dynamically like so:
var objSetter = function(prop,val){
obj[prop] = val;
}
No ...
122
votes
12
answers
43k
views
Calling closure assigned to object property directly
I would like to be able to call a closure that I assign to an object's property directly without reassigning the closure to a variable and then calling it. Is this possible?
The code below doesn't ...