Search This Blog

2022/08/29

Convert an Object to an Array in JavaScript

const arr = {

    first: '1',

    second: '2'

};

 

Object.keys(arr)

  • [ 'first', ' second' ]

 

Object.values(arr)

  • [ '1', ' 2' ]

 

Object.entries(arr)

  • [ [ 'first', '1' ], [ ' second ', '2' ] ]