Answers for "oject to array convert in js"

4

how to convert object to array in javascript

// how to convert object to array in javascript
// Object.entries()
const credits = { producer: 'John', director: 'Jane', assistant: 'Peter' };
const arr = Object.entries(credits);
console.log(arr);

/** Output:
[ [ 'producer', 'John' ],
  [ 'director', 'Jane' ],
  [ 'assistant', 'Peter' ]
]
**/
// convert to values array
// Object.values()
console.log(Object.values(credits));
// [ 'John', 'Jane', 'Peter' ]
Posted by: Guest on January-20-2022
0

Javascript convert object value to array

function pluck(array, key) {
  return array.map(o => o[key]);
}
Posted by: Guest on April-15-2022

Code answers related to "Javascript"

Browse Popular Code Answers by Language