Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
Sort based on keys
//nodejs v4.2.6 var arr = [{id: 588, name: "1 ex"}, {id: 592, name: "11 ex"}, {id: 607, name: "2 ex"}, {id: 580, name: "3 ex"}, {id: 596, name: "4 ex"}]; var map = {} for(var item of arr) { map[item["name"]] = item; } var arr = arr.map(function(item){return item["name"]}).sort(function(a, b){ var a = parseInt(a.split(' ')[0]); var b = parseInt(b.split(' ')[0]); return a-b; }).map(function(name){ return map[name]; }) console.log(arr);
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
Add property to object
Include object in a query string
Counting digits
Union of two sorted arrays
Union of two sorted arrays
Holyboi
Tree Structure
lodash
Add items on Set
problem_name
Please log in to post a comment.