Returns the value of the first element in the array that satisfies the provided testing function, or undefined if no appropriate element is found. Returns a new array containing all elements of the calling array for which the provided filtering function returns true. ()įills all the elements of an array from a start index to an end index with a static value. Returns true if every element in the calling array satisfies the testing function. Returns a new array iterator object that contains the key/value pairs for each index in an array. ()Ĭopies a sequence of array elements within an array. Returns a new array that is the calling array joined with other array(s) and/or value(s). Accepts negative integers, which count back from the last item. Returns the array item at the given index. It mutates the array in-place, doesn't accept thisArg, and may invoke the callback multiple times on an index. The sort() method also takes a callback function, but it is not an iterative method. There are two other methods that take a callback function and run it at most once for each element in the array, but they have slightly different signatures from typical iterative methods (for example, they don't accept thisArg): In particular, every(), find(), findIndex(), findLast(), findLastIndex(), and some() do not always invoke callbackFn on every element - they stop iteration as soon as the return value is determined. The thisArg argument is irrelevant for any callbackFn defined with an arrow function, as arrow functions don't have their own this binding.Īll iterative methods are copying and generic, although they behave differently with empty slots. The this value ultimately observable by callbackFn is determined according to the usual rules: if callbackFn is non-strict, primitive this values are wrapped into objects, and undefined/ null is substituted with globalThis. The thisArg argument (defaults to undefined) will be used as the this value when calling callbackFn. What callbackFn is expected to return depends on the array method that was called. The array that the method was called upon. The index of the current element being processed in the array. The current element being processed in the array. Where callbackFn takes three arguments: element The following table lists the methods that mutate the original array, and the corresponding non-mutating alternative: Mutating methodĪn easy way to change a mutating method into a non-mutating alternative is to use the spread syntax or slice() to create a copy first: Conceptually, they are not copying methods either. Group() and groupToMap() do not use to create new arrays for each group entry, but always use the plain Array constructor. The following methods always create new arrays with the Array base constructor:
0 Comments
Leave a Reply. |