That function should take two parameters (the two items to be compared): then, it will return 0 if they are equal, a negative number if the first parameter takes precedence, or a positive number of the second parameter should come first. ![]() Fortunately, we can pass a function to the sort method. Usually, this is terrible consider sorting the numbers 0 - 10 alphabetically. If you don't pass it any parameters, it will convert the objects in the array to strings, sort them pseudo-alphabetically, and return them. ![]() ![]() So, how exactly does sorting work in JavaScript? It's not too complicated: any array object has a sort method.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |