store all the values in a object javascript code example

Example 1: javascript object to array

//ES6 Object to Array

const numbers = {
  one: 1,
  two: 2,
};

console.log(Object.values(numbers));
// [ 1, 2 ]

console.log(Object.entries(numbers));
// [ ['one', 1], ['two', 2] ]

Example 2: javascript access property values list of objects

// 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] ]

Tags:

Css Example