How to convert an object to an array in Node.js

1 Answer

0 votes
const obj = {
    q: 'NodeJS',
    lang: 'en',
    limit: 13
};

const arr_keys = Object.keys(obj);
console.log(arr_keys);

const arr_values = Object.values(obj);
console.log(arr_values);

const arr_all = Object.entries(obj);
console.log(arr_all);


  
  
/*
run:
  
[ 'q', 'lang', 'limit' ]
[ 'NodeJS', 'en', 13 ]
[ [ 'q', 'NodeJS' ], [ 'lang', 'en' ], [ 'limit', 13 ] ]
  
*/

 



answered May 24, 2022 by avibootz

Related questions

3 answers 162 views
1 answer 151 views
1 answer 129 views
1 answer 147 views
1 answer 96 views
1 answer 129 views
...