Native JavaScript Sort Method - Array.sort()

preview_player
Показать описание
note: youtube won't allow angle brackets in the description, so i have changed the functions to ES5 to avoid using the arrow functions, and replaced the less than operator.

Numbers:
sort numbers with the following compare function passed in:

Letters:
sort words with the following compare function passed in:

Array of Objects:
to sort by a specific property, just reference that property when comparing:
let people = [{name: 'Bob', age: 45}, {name: 'Alex', age: 23}, {name: 'John', age: 2}, {name: 'carrie', age: 3}];
//by name:
//by age:

Resources:
Рекомендации по теме
Комментарии
Автор

Excellent content and sweetest voice ever!

marcoanello
visit shbcf.ru