Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

sort array of objects

function compareAge(a, b) {

    return a.age - b.age;
}

const students = [{name: 'Sara', age:2},{name: 'John', age:1}, {name: 'Jack', age:0}];

console.log(students.sort(compareAge));
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #sort #array #objects
ADD COMMENT
Topic
Name
6+7 =