Q:

object values javascript

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

console.log(Object.values(object1));
// expected output: Array ["somestring", 42, false]
2
//Supposing fooObj to be an object

fooArray = Object.entries(fooObj);

fooArray.forEach(([key, value]) => {
  console.log(key); // 'one'
  console.log(value); // 1
})
4
object.value

#or

object.name
1
Object.values(obj)
4
const object1 = {
  a: 'somestring',
  b: 42,
  c: false
};

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

// expected output: Array ["somestring", 42, false]
7
// Access all properties and values in a JS object:
let valuesArray = Object.entries(MyObject);
  
   for (let value of valuesArray) { 
       document.write(value + "<br>"); // value is the property,value pair
   } 
/* Result: propName,value
           propName,value
 		   ...

For clarity: */
let person = {
  name: "Piet",
  age: 42
};

Object.keys(person) // = ["name", "age"]
Object.values(person) // = ["Piet", 42]
Object.entries(person) // = [ ["name","Piet"], ["age",42] ]
2
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
4
Object.values(object1)
0

New to Communities?

Join the community