HomeToolsAbout

Objects

Find key or value presence in object

const 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

Extract Values from Array of Objects (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]

Check if Object is empty

const someObject = {}; const isObjectEmpty: Boolean = Object.entries(someObject).length === 0;
AboutContact