sort array of objects by string property value
function compareFirstNames( a, b ) {
if ( a.first_name < b.first_name ){
return -1;
}
if ( a.first_name > b.first_name ){
return 1;
}
return 0;
}
var people =[
{"first_name":"Carol", "age":29},
{"first_name":"Anna", "age":32},
{"first_name":"Bob", "age":32}
];
people.sort( compareFirstNames ); //people is now sorted by first name from a-z
Also in JavaScript:
- moment format datetime postgresql
- jest input value
- caesar cipher javascript code
- javascript remove parameters from current url
- jquery number format comma
- else in javascript
- sort array based on another array
- button style in jquery datatable
- js filter array
- turning an hex code to rgb discord.js
- ajax data post call in javascript
- how to generate a random number between 1 and 6 in javascript
- javascript tutorial
- pass value from one component to another in polymer
- javascript add items to array
- jquery cdn w3schools
- how to Write a program that simulates a coin toss using random method of Javascript Math class
- parsefloat jquery
- node dotenv
- javascript array stackoverflow
- use effect react
- jquery select element with data
- css defer async
- firstElementChild jquery equivalent