Skip to content Skip to sidebar Skip to footer

Form Array Of Property Names Found In A Javascript Object

I have the following object var columns = {ContributionType: 'Employer Contribution', Employee1: '0', Employee2: '0', Employee3: '0'

Solution 1:

Object.keys()

var columns = {ContributionType: "Employer Contribution",
               Employee1: "0",
               Employee2: "0",
               Employee3: "0"
              };
var keys = Object.keys(columns);
console.log(keys);

Solution 2:

var arr=[];
for (var key in columns)
{
//by using hasOwnProperty(key) we make sure that keys of//the prototype are not included if anyif(columns.hasOwnProperty(key))
{
    arr.push(key);
}
}

Post a Comment for "Form Array Of Property Names Found In A Javascript Object"