key
or value
presence in objectconst targetToLookFor: string = "targetKey"; const someObject = { "key1": "val1", "key2": "val2", "targetKey": "val3" }; const result = Object.keys(someObject).find(key => targetToLookFor == key); // returns "targetKey" // `undefined` returned when not found
JSON
)Extracting key
or values
from Objects.
// input array of objects const data = [ { foo: 1, bar: 2}, { foo: 3, bar: 4}, { foo: 5, bar: 6} ]; const foosFromData = items.map(record => record.foo); const foosFromData2 = items.map(({ foo }) => foo); // Output: [1, 3, 5]
const someObject = {}; const isObjectEmpty: Boolean = Object.entries(someObject).length === 0;