javascript select keys from object code example
Example 1: js get object keys
myObject = {
"key": "value"
}
Object.keys(myObject);
Example 2: js select keys from object
const object = { a: 5, b: 6, c: 7 };
const picked = (({ a, c }) => ({ a, c }))(object);
console.log(picked);
Example 3: get keys of object js
var buttons = {
foo: 'bar',
fiz: 'buz'
};
for ( var property in buttons ) {
console.log( property );
}
Example 4: javascript subset of object array matching certain property
let cities = [
{name: 'Los Angeles', population: 3792621},
{name: 'New York', population: 8175133},
{name: 'Chicago', population: 2695598},
{name: 'Houston', population: 2099451},
{name: 'Philadelphia', population: 1526006}
];
let bigCities = cities.filter(function (e) {
return e.population > 3000000;
});
[
{ name: 'Los Angeles', population: 3792621 },
{ name: 'New York', population: 8175133 }
]