In a JSON array, each object has a key called popularity
whose value is integer with no quotes.
There are also very few objects in the array which have value as undefined
for this popularity
key.
How do you sort the array, using JavaScript (ECMAScript 2015) preferred, by popularity
key descending largest to smallest, skip or move the undefined
ones to the bottom.
The following is not working
objGroup = objGroup.sort((a,b) => b.popularity - a.popularity ); // or
objGroup = objGroup.sort((a,b) => parseInt(b.popularity) - parseInt(b.popularity) );
EDIT
found
From MDN:
In JavaScript 1.2, this method no longer converts undefined elements to null; instead it sorts them to the high end of the array
From the spec, 15.4.4.11 :
Because non-existent property values always compare greater than undefined property values, and undefined always compares greater than any other value, undefined property values always sort to the end of the result, followed by non-existent property values.