[Js articles] Realize the sorting function of strings and object arrays

How to sort arrays of string type, number type array and object type array in Js? Not much nonsense, on the size!

1. Sort the numbers

insert image description here
insert image description here

2. Sort the strings

insert image description here
insert image description here

3. Sorting of objects

insert image description here
Summary: Whether it is the sorting function of objects, strings or numbers, you need to use the sort method that comes with js itself. It can be realized with a little modification. If you want to sort in reverse, you can use reverse(). method will do. Do you remember?

Guess you like

Origin blog.csdn.net/s398511733/article/details/123715865