keys from object javascript code example
Example 1: get keys objet javascript
var foo = {
'alpha': 'puffin',
'beta': 'beagle'
};
var keys = Object.keys(foo);
console.log(keys)
Example 2: js get object keys
myObject = {
"key": "value"
}
Object.keys(myObject);
Example 3: js object keys
var myObj = {no:'u',my:'sql'}
var keys = Object.keys(myObj);
Example 4: get keys of object js
var buttons = {
foo: 'bar',
fiz: 'buz'
};
for ( var property in buttons ) {
console.log( property );
}
Example 5: how to get keys in an object javascript
Object.keys(whateverYourObjectIsCalled)
Example 6: js create object with keys
var users = [{userId: "1", name: 'harald'}, {userId: "2", name: 'jamie'}];
var obj = {};
users.forEach(user => {
obj = {
...obj,
[user.userId]: user,
}
})
console.log(obj)