Answers for "listing all attributes of an object js"

2

get array of all property in object array

objArray = [ { foo: 1, bar: 2}, { foo: 3, bar: 4}, { foo: 5, bar: 6} ];
let result = objArray.map(a => a.foo); //[1,3,5]
//OR
let result = objArray.map(({ foo }) => foo) //[1,3,5]
Posted by: Guest on April-20-2021
1

display all properties of object in javascript

var showKeys = function(obj){
   var keys = [];
   for(var key in obj){
      keys.push(key.toString() + "\n");
   }
   console.log("{\n" + keys + "}");
}
Posted by: Guest on August-13-2021

Code answers related to "listing all attributes of an object js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language