js get object where value code example

Example 1: object to array javascript

Object.values(obj)

Example 2: object values

const object1 = {
  a: 'somestring',
  b: 42,
  c: false
};

console.log(Object.values(object1));

// expected output: Array ["somestring", 42, false]

Example 3: get all entries in object as array hjs

const object1 = {
  a: 'somestring',
  b: 42
};

for (let [key, value] of Object.entries(object1)) {
  console.log(`${key}: ${value}`);
}

// expected output:
// "a: somestring"
// "b: 42"
// order is not guaranteed

Example 4: javascript get object where

myArray = [{'id':'73','foo':'bar'},{'id':'45','foo':'bar'}, etc.]

myArray.find(x => x.id === '45').foo;

Tags:

Css Example