Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

sort array of objects javascript by value

const subjects = [
    { "name": "Math", "score": 81 },
    { "name": "English", "score": 77 },
    { "name": "Chemistry", "score": 87 },
    { "name": "Physics", "score": 84 }
];

// Sort in ascending order - by name
subjects.sort((a, b) => (a.name > b.name) ? 1: -1);

console.log(subjects);
Source by devsheet.com #
 
PREVIOUS NEXT
Tagged: #sort #array #objects #javascript
ADD COMMENT
Topic
Name
2+4 =