๐ 24 Array Methods in JavaScript:
Mega Thread ๐งต ๐
#LearnToCode #CodeNewbie
1) concat():
๐น Concatenates (joins) two or more arrays.
๐น Returns a new array, containing the joined arrays.
๐น Does not change the existing arrays.
2) copyWithin():
๐น Copies array elements to another position in the array.
๐น Overwrites the existing values.
๐น Does not add items to the array.
3) every():
๐น Executes a function for each array element.
๐น Returns `true` if the function returns true for all elements, otherwise returns `false`.
๐น Does not execute the function for empty elements.
๐น Does not change the original array.
4) fill():
๐น Fills specified elements in an array with a value.
๐น Overwrites the original array.
๐น Start and end position can be specified. If not, all elements will be filled.
5) filter():
๐น Creates a new array filled with elements that pass a test provided by a function.
๐น Does not execute the function for empty elements.
๐น Does not change the original array.
6) find():
๐น Returns the value of the first element that passes a test. Returns `undefined` if no elements are found.
๐น Executes a function for each array element.
๐น Does not execute the function for empty elements.
๐น Does not change the original array.
7) findIndex():
๐น Returns the the index (position) of the first element that passes a test. Returns -1 if no match is found.
๐น Executes a function for each array element.
๐น Does not execute the function for empty elements.
๐น Does not change the original array.
8) from():
๐น Returns an array from any object with a length property.
9) includes():
๐น Returns `true` if an array contains a specified value, otherwise returns `false`.
๐น This method is case sensitive.
10) indexOf():
๐น Returns the first index (position) of a specified value. Returns -1 if the value is not found.
๐น Starts at a specified index and searches from left to right.
๐น Negative start values counts from the last element (but still searches from left to right).
11) isArray():
๐น Returns `true` if an object is an array, otherwise `false`.
12) join():
๐น Returns an array as a string.
๐น Does not change the original array.
13) lastIndexOf():
๐น Returns the last index (position) of a specified value. Returns -1 if the value is not found.
๐น Starts at a specified index and searches from right to left.
๐น Negative start values counts from the last element (but still searches from right to left).
14) map():
๐น Creates a new array from calling a function for every array element.
๐น Calls a function once for each element in an array.
๐น Does not execute the function for empty elements.
๐น Does not change the original array.
15) pop():
๐น Removes (pops) the last element of an array.
๐น Changes the original array.
๐น Returns the removed element.
16) push():
๐น Adds new items to the end of an array.
๐น Changes the length of the array.
๐น Returns the new length.
17) reduce():
๐น Executes a reducer function for each array element.
๐น Returns a single value: the function's accumulated result.
๐น Does not execute the function for empty array elements.
๐น Does not change the original array.
18) reverse():
๐น Reverses the order of the elements in an array.
๐น Overwrites the original array.
19) shift():
๐น Removes the first item of an array.
๐น Changes the original array.
๐น Returns the shifted element.
20) slice():
๐น Returns selected elements in an array, as a new array.
๐น Selects from a given start, up to a (not inclusive) given end.
๐น Does not change the original array.
21) some():
๐นChecks if any array elements pass a test.
๐น Executes the callback function once for each array element.
๐น Returns true (and stops) if the function returns true for one of the array elements. Otherwise returns false.
22) sort():
๐น Sorts the elements of an array.
๐น Overwrites the original array.
๐น Sorts the elements as strings in alphabetical and ascending order.
23) splice():
๐น Adds and/or removes array elements.
๐น Overwrites the original array.
24) unshift():
๐น Adds new elements to the beginning of an array.
๐น Overwrites the original array.
That's a wrap!
If you found it useful, please consider:
๐นFollow me @cgrkzlkn for more content on HTML, CSS and JavaScript ๐งโ๐ป
๐นLike โค๏ธ
๐นRetweet the first tweet โก๏ธ
You can read unrolled version of this thread:
threadreaderapp.com/thread/1553468โฆ
Share this Scrolly Tale with your friends.
A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.