array of objects in javascript short 1

array of objects in javascript short

objs.sort((a, b) => a.last_nom.localeCompare(b.last_nom));

Here is what the above code is Doing:
1. We’re creating a new array called sorted_objs.
2. We’re using the sort() method to sort the array.
3. We’re using the localeCompare() method to compare the last_nom property of each object.
4. We’re using the arrow function to return the result of the comparison.

Similar Posts