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

1 Answer

0 votes
const obj = {
  id: 111765,
  name: "Albus Dumbledore",
  academicrank: "Professor"
};
 
const arr = Object.keys(obj);

console.log(arr); 

console.log(arr[0]); 

console.log(arr[0][0]); 
console.log(arr[0][1]); 
 
   
     
     
/*
run:
     
[ 'id', 'name', 'academicrank' ]
id
i
d
     
*/

 



answered Feb 25, 2022 by avibootz

Related questions

1 answer 150 views
1 answer 145 views
2 answers 148 views
1 answer 128 views
1 answer 129 views
...