javascript object value code example

Example 1: object values javascript

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

console.log(Object.values(object1));
// expected output: Array ["somestring", 42, false]

Example 2: javascript object to array

//Supposing fooObj to be an object

fooArray = Object.entries(fooObj);

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

Example 3: js object keys

var myObj = {no:'u',my:'sql'}
var keys = Object.keys(myObj);//returnes the array ['no','my'];

Example 4: js get all values of object

Object.values(object1)

Example 5: js create object with properties

function Car(make, model, year) {
  this.make = make;
  this.model = model;
  this.year = year;
}