๐Array Methods Explained As Emojis
1. Array.push()
Array.push()Adds one or more elements to the end of an array. Or grows a farm.
let livestock = ["๐ท", "๐ฎ", "๐"];livestock.push("๐ด", "๐ฎ");// console.log(livestock);// ["๐ท", "๐ฎ", "๐", "๐ด", "๐ฎ"]_Documentation on _MDN
2. Array.from()
Array.from()Creates a new array from an array-like or iterable object. Or separates some wild animals.
const wild = "๐ป๐ฏ๐ฆ";const tamed = Array.from(wild);// console.log(tamed);// ["๐ป", "๐ฏ", "๐ฆ"]_Documentation on _MDN
3. Array.concat()
Array.concat()Merges two or more arrays into a single new one. Or brings different worlds together.
const dogs = ["๐ถ", "๐ถ"];const cats = ["๐ฑ", "๐ฑ", "๐ฑ"];const pets = dogs.concat(cats);// console.log(pets);// ["๐ถ", "๐ถ", "๐ฑ", "๐ฑ", "๐ฑ"]_Documentation on _MDN
4. Array.every()
Array.every()Checks if all elements of an array pass the test. Or detects intruders.
_Documentation on _MDN
5. Array.fill()
Array.fill()Replaces the elements of an array from start to end index with a given value. Or grows some trees.
_Documentation on _MDN
6. Array.filter()
Array.filter()Creates a new array containing all elements passing the test. Or predicts your relationship status.
* You might wonder, why the string length is divided by two here. The reason is that emojis actually are represented by a pair of code points, also known as a surrogate pair.
Try "๐ฉ".length in your console and see for yourself. More information in this article.
_Documentation on _MDN
7. Array.flat()
Array.flat()Creates a new array containing all elements from all sub-arrays up to a given depth. Or cracks any safe.
_Documentation on _MDN
8. Array.includes()
Array.includes()Checks if an array contains a specific element. Or finds the secret sweet tooth.
_Documentation on _MDN
9. Array.join()
Array.join()Concatenates all array elements to one single string, using an optional separator. Or builds local area networks.
_Documentation on _MDN
10. Array.map()
Array.map()Calls a function on each array element and returns the result as new array. Or feeds all hungry monkeys.
_Documentation on _MDN
11. Array.reverse()
Array.reverse()Reverses the order of elements in an array. Or decides the outcome of a race.
Note that this method is destructive, it modifies the original array. So after line 2 of this example rabbitWins and hedgehogWins both have the value ["๐ฆ", "๐"]
_Documentation on _MDN
12. Array.slice()
Array.slice()Creates a new array from copying a portion of an array defined by start and end index. Or cheats in an exam.
_Documentation on _MDN
13. Array.some()
Array.some()Tests if at least one element of an array passes the test. Or finds if some participants of your meeting forgot to mute their mic.
_Documentation on _MDN
14. Array.sort()
Array.sort()Sorts all elements of an array. Or organizes your bookshelf again.
_Documentation on _MDN
15. Array.splice()
Array.splice()Removes, replaces or adds elements to an array. Or changes the weather.
_Documentation on _MDN
16. Array.unshift()
Array.unshift()Adds one or more elements to the beginning of an array. Or couples a loco.
_Documentation on _MDN
Last updated
Was this helpful?
