Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

angularjs How to sort a specific value in a map

var map = new Map();
map.set('0001', {lastChat: {message: 'test', time: 1640063014931}});
map.set('0002', {lastChat: {message: 'test', time: 1640063014930}});

var sortedMap = new Map([...map].sort((a, b) => a[1].lastChat.time - b[1].lastChat.time));

console.log(sortedMap.entries())
//Output : MapIterator {'0002' => {…}, '0001' => {…}}
 
PREVIOUS NEXT
Tagged: #angularjs #How #sort #specific #map
ADD COMMENT
Topic
Name
5+3 =