Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
140
rated 0 times [  147] [ 7]  / answers: 1 / hits: 44434  / 8 Years ago, wed, november 16, 2016, 12:00:00
 var legend=[{min:0,
max:first_color,
color:#1a9850
},
{
min:first_color,
max:sec_color,
color:#fee08b
},
{
min:sec_color,
max:thrd_color,
color:#ff3300
},
{
min:thrd_color,
max:frth_color,
color:#d73027
Abc:gsfg
}

];


I'd like to find out each object's property count. E.g. the first 3 objects have 3 properties and 4th one has 4 props, etc.


More From » json

 Answers
2

Iterate over the array and get object property names count.





var legend = [{
min: 0,
max: 'first_color',
color: #1a9850
}, {
min: 'first_color',
max: 'sec_color',
color: #fee08b
}, {
min: 'sec_color',
max: 'thrd_color',
color: #ff3300
}, {
min: 'thrd_color',
max: 'frth_color',
color: #d73027,
Abc: gsfg
}];

var res = legend.map(function(v) {
console.log(Object.keys(v).length);
return Object.keys(v).length;
});

console.log(res);




[#60051] Sunday, November 13, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
zariahdiamondz

Total Points: 649
Total Questions: 109
Total Answers: 88

Location: Tajikistan
Member since Thu, Apr 14, 2022
2 Years ago
;