Say I have an array:
var array = [ { first: 'qwe123', second: 1234 }, {..}, .. ];
I want to sort an array by second keys value(1234) in descending order and put all elements' values into one string. Is it possible to do so?
Say I have an array:
var array = [ { first: 'qwe123', second: 1234 }, {..}, .. ];
I want to sort an array by second keys value(1234) in descending order and put all elements' values into one string. Is it possible to do so?
You may use:
The example:
var array = [ {first: 'qwe123', second: 1},
{first: 'qwe123', second: 2},
{first: 'qwe123', second: 3},
{first: 'qwe123', second: 4}];
var result = array.sort(function(a, b) {
return +b.second - +a.second;
}).map(function(ele, idx) {
return ele.second;
}).join(', ');
console.log(result);