How to get all property values of an object as an array in JavaScript

3 Answers

0 votes
let obj = {
  id: 383912,
  name: "Albus Dumbledore",
  academicrank: "Professor"
};

let valuesArray = Object.keys(obj).map(function (key) {
  return obj[key];
});

console.log(valuesArray);


  
    
    
/*
run:

[383912, "Albus Dumbledore", "Professor"]
    
*/

 



answered Jan 30, 2021 by avibootz
0 votes
let obj = {
  id: 383912,
  name: "Albus Dumbledore",
  academicrank: "Professor"
};

const valueArray = Object.keys(obj).map(key => obj[key]);

console.log(valueArray);


  
    
    
/*
run:

[383912, "Albus Dumbledore", "Professor"]
    
*/

 



answered Jan 30, 2021 by avibootz
0 votes
const obj = {
  id: 383912,
  name: "Albus Dumbledore",
  academicrank: "Professor"
};
 
const valueArray = Object.values(obj);
 
console.log(valueArray);
 
 
   
     
     
/*
run:
 
[383912, "Albus Dumbledore", "Professor"]
     
*/

 



answered Jan 30, 2021 by avibootz
edited Jul 5, 2022 by avibootz

Related questions

...