Loading topic
Array.prototype.sort and Array.prototype.splice behave, arrow functions, and the difference between primitive values and object references. The previous chapter showed how in-place mutation causes bugs. This one covers the group o5 min readArray.prototype.sort, can write arrow functions, and understand the difference between primitive values and object references. It covers the comparator contract that sort and toSorted share. The next chapter covers what `t5 min readArray.prototype.sort behaves, including its comparator argument. It also assumes you can read arrow functions and know that objects are passed by reference. The earlier chapter on comparators explained why the default so4 min readsplice is the most flexible array method in JavaScript. It can insert, remove, and replace elements in one call. It also mutates the array it is called on, and it returns the deleted elements instead of the updated array. toSpliced keeps the flexibility and fixes both problems. It takes the same5 min readarr[i] = value) works, and that objects are passed by reference. It covers Array.prototype.with, the copying counterpart of bracket assignment. Negative indices and out-of-range errors get their own chapt5 min readwith(index, value) returns a copy with one element replaced, as covered in the previous chapter. You should also be comfortable with zero-based indexing, bracket assignment (arr[i] = x), and try...catch. The chapter covers two rules that set with apa4 min readtoSorted, toSpliced, and with work, and that you are comfortable with Array.prototype.reverse, arrow functions, and the difference between primitive values and object references.4 min readtoSorted, toSpliced, and with return new arrays. It also assumes you understand the difference between primitive values and object references. The chapter covers a question those methods leave open: when the array holds objects, how much of it is actua4 min readtoSorted, toSpliced, toReversed, and with work on their own. It also assumes you know that their copies are shallow. The focus here is on combining them. Each copying method returns a new array, so you can call another method on its result. The resul5 min readtoSorted, toSpliced, and with from the earlier chapters, and that you understand shallow copies. It also assumes basic familiarity with React's useState hook and Redux reducers. You do not need a React project to run most examples. The reducer code runs 5 min readsort, splice, and the spread operator, and that you have already worked through toSorted, toSpliced, and with earlier in this tutorial. Here we look at where these methods exist, how to check for them at runtime, and how to write fallbacks that behave the same5 min readlength are, that you have used sort and splice, and that you have met toSorted, toSpliced, and with in earlier chapters. It covers one narrow rule with practical effects: the copying methods never produce holes. Any hole they read come5 min readtoSorted, toSpliced, with, and toReversed behave on ordinary arrays. It also assumes you know what Function.prototype.call does and that you have seen class ... extends Array. Two questions remain. First, what happens when one of these methods ru5 min readtoSorted and with behave on ordinary arrays. It also assumes you know what a typed array is: a fixed-length view over an ArrayBuffer whose elements all share one numeric type, such as Uint8Array or Float64Array. ES2023 added copying methods to type4 min read