Loading topic
sort() with no arguments looks like the obvious way to put an array in order. For strings it often does what you expect. For numbers it usually doesn't. This chapter explains what the default sort actually does, so later chapters can build on that when you write your own ordering rules.3 min readsort() compares elements as strings by default. Here you replace that default with a rule of your own.3 min readsort mutates while toSorted returns a copy, and you are comfortable with arrays of objects. Here you will learn what a stable sort is, what the language guarantees, and how that guarantee affects the code you write.3 min readsort() without a comparator orders elements by UTF-16 code units. Here you will make string sorting match what a human reader expects.3 min readArray.prototype.sort works, how comparator functions work, and what toSorted does. Typed arrays use the same method names, but they behave differently in a few ways that matter.3 min readindexOf, lastIndexOf, and includes. All three do a linear search. A linear sea3 min readindexOf and includes. Real data rarely works that way. You usually want "the first paid order" or "any user over 18", which is a condition, not a value. This chapter assumes you are comfortable with arrow functions, objects and property access2 min readsort() compares elements as strings, and have used linear search methods such as indexOf and includes.3 min readindexOf, includes, find, filter) and the binary search function from the previous chapter. It also assumes you are comfortable with object property access and arrow functions. Here we look at what each search approach costs and when 3 min read