My Docs
Array-Methods-Lesson
Array-Methods-Lesson
  • Home
    • General Questions
    • Lesson Plan
    • Advice
  • ๐Ÿ‘จ๐Ÿ’ป Methods
    • ๐Ÿ”—Array.forEach()
      • forEach-Questions
    • ๐ŸšฎArray.filter()
      • Filter Questions
    • ๐Ÿ’ฉArray.reduce()
      • Reduce Questions
    • ๐Ÿ—บ๏ธArray.map()
      • Map Questions
    • Native Implementation
  • Background
    • ๐Ÿ˜ถMutability
    • ๐ŸผArray Basics
    • ๐Ÿ”™Background
    • ๐Ÿ“ฒCallback Functions
    • ๐Ÿ”๏ธHigher Order Functions
    • ๐Ÿง˜Difference Between Functions & Methods...
    • โžก๏ธFat Arrow Syntax
    • ๐Ÿ’ฑDoes It Mutateยฟ
    • First Class Functions
  • ๐Ÿ“–Resources
    • ๐Ÿ“ฐCheat Sheet
      • ๐Ÿ‘ทโ€โ™€๏ธ๐Ÿ‘ทโ™€ ๐Ÿ‘ทโ™€ ๐Ÿ‘ทโ™€ ๐Ÿ‘ทโ™€ Examples
    • ๐Ÿค“Other Array Methods
    • Examples
      • Refactor
  • ๐Ÿ‘ฝMiscellaneous
    • ๐ŸArray Methods Explained As Emojis
Powered by GitBook
On this page
  • 1. Array.push()
  • 2. Array.from()
  • 3. Array.concat()
  • 4. Array.every()
  • 5. Array.fill()
  • 6. Array.filter()
  • 7. Array.flat()
  • 8. Array.includes()
  • 9. Array.join()
  • 10. Array.map()
  • 11. Array.reverse()
  • 12. Array.slice()
  • 13. Array.some()
  • 14. Array.sort()
  • 15. Array.splice()
  • 16. Array.unshift()

Was this helpful?

Edit on GitHub
  1. Miscellaneous

Array Methods Explained As Emojis

PreviousRefactor

Last updated 3 years ago

Was this helpful?

1. 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 _

2. 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 _

3. 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 _

4. Array.every()

Checks if all elements of an array pass the test. Or detects intruders.

const visitors   = ["๐Ÿง‘", "๐Ÿ‘ฝ", "๐Ÿง‘", "๐Ÿง‘", "๐Ÿค–"];const isHuman    = e => e === "๐Ÿง‘";const onlyHumans = visitors.every(isHuman);// console.log(onlyHumans);// false

5. Array.fill()

Replaces the elements of an array from start to end index with a given value. Or grows some trees.

let seeds = ["๐ŸŒฑ", "๐ŸŒฑ", "๐ŸŒฑ", "๐ŸŒฑ", "๐ŸŒฑ"];seeds.fill("๐ŸŒณ", 1, 4);// console.log(seeds);// ["๐ŸŒฑ", "๐ŸŒณ", "๐ŸŒณ", "๐ŸŒณ", "๐ŸŒฑ"]

6. Array.filter()

Creates a new array containing all elements passing the test. Or predicts your relationship status.

const guests  = ["๐Ÿ‘ฉ๐Ÿ‘จ", "๐Ÿ‘ฉ๐Ÿ‘ฉ", "๐Ÿ‘จ", "๐Ÿ‘ฉ", "๐Ÿ‘จ๐Ÿ‘จ"];const singles = guests.filter(g => g.length/2 === 1); // *// console.log(singles);// ["๐Ÿ‘จ", "๐Ÿ‘ฉ"]

7. Array.flat()

Creates a new array containing all elements from all sub-arrays up to a given depth. Or cracks any safe.

const savings = ["๐Ÿ’ต", ["๐Ÿ’ต", "๐Ÿ’ต"], ["๐Ÿ’ต", "๐Ÿ’ต"], [[["๐Ÿ’ฐ"]]]];const loot    = savings.flat(3)// console.log(loot);// ["๐Ÿ’ต", "๐Ÿ’ต", "๐Ÿ’ต", "๐Ÿ’ต", "๐Ÿ’ต", "๐Ÿ’ฐ"];

8. Array.includes()

Checks if an array contains a specific element. Or finds the secret sweet tooth.

const food   = ["๐Ÿฅฆ", "๐Ÿฅฌ", "๐Ÿ…", "๐Ÿฅ’", "๐Ÿฉ", "๐Ÿฅ•"];const caught = food.includes("๐Ÿฉ");// console.log(caught);// true

9. Array.join()

Concatenates all array elements to one single string, using an optional separator. Or builds local area networks.

const devices = ["๐Ÿ’ป", "๐Ÿ–ฅ๏ธ", "๐Ÿ–ฅ๏ธ", "๐Ÿ’ป", "๐Ÿ–จ๏ธ"];const network = devices.join("ใ€ฐ๏ธ");// console.log(network);// "๐Ÿ’ปใ€ฐ๏ธ๐Ÿ–ฅ๏ธใ€ฐ๏ธ๐Ÿ–ฅ๏ธใ€ฐ๏ธ๐Ÿ’ปใ€ฐ๏ธ๐Ÿ–จ๏ธ"

10. Array.map()

Calls a function on each array element and returns the result as new array. Or feeds all hungry monkeys.

const hungryMonkeys = ["๐Ÿ’", "๐Ÿฆ", "๐Ÿฆง"];const feededMonkeys = hungryMonkeys.map(m => m + "๐ŸŒ");// console.log(feededMonkeys);// ["๐Ÿ’๐ŸŒ", "๐Ÿฆ๐ŸŒ", "๐Ÿฆง๐ŸŒ"]

11. Array.reverse()

Reverses the order of elements in an array. Or decides the outcome of a race.

let   rabbitWins   = ["๐Ÿ‡", "๐Ÿฆ”"];const hedgehogWins = rabbitWins.reverse();// console.log(hedgehogWins);// ["๐Ÿฆ”", "๐Ÿ‡"]

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 ["๐Ÿฆ”", "๐Ÿ‡"]

12. Array.slice()

Creates a new array from copying a portion of an array defined by start and end index. Or cheats in an exam.

const solutionsOfClassmates = ["๐Ÿ“ƒ", "๐Ÿ“‘", "๐Ÿ“„", "๐Ÿ“"];const myOwnSolutionReally   = solutionsOfClassmates.slice(2, 3);// console.log(myOwnSolutionReally);// ["๐Ÿ“„"]

13. 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.

const participants = ["๐Ÿ”‡", "๐Ÿ”‡", "๐Ÿ”Š", "๐Ÿ”‡", "๐Ÿ”Š"];const isLoud       = p => p === "๐Ÿ”Š";const troubles     = participants.some(isLoud);// console.log(troubles);// true

14. Array.sort()

Sorts all elements of an array. Or organizes your bookshelf again.

let books = ["๐Ÿ“•", "๐Ÿ“—", "๐Ÿ“•", "๐Ÿ“’", "๐Ÿ“—", "๐Ÿ“’"];books.sort();// console.log(books);// ["๐Ÿ“’", "๐Ÿ“’", "๐Ÿ“•", "๐Ÿ“•", "๐Ÿ“—", "๐Ÿ“—"]

15. Array.splice()

Removes, replaces or adds elements to an array. Or changes the weather.

let weather = ["โ˜๏ธ", "๐ŸŒง๏ธ", "โ˜๏ธ"];weather.splice(1, 2, "โ˜€๏ธ");// console.log(weather);// ["โ˜๏ธ", "โ˜€๏ธ"]

16. Array.unshift()

Adds one or more elements to the beginning of an array. Or couples a loco.

let train = ["๐Ÿšƒ", "๐Ÿšƒ", "๐Ÿšƒ", "๐Ÿšƒ"];train.unshift("๐Ÿš‚");// console.log(train);// ["๐Ÿš‚", "๐Ÿšƒ", "๐Ÿšƒ", "๐Ÿšƒ", "๐Ÿšƒ"]

_Documentation on _

_Documentation on _

* 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 .

_Documentation on _

_Documentation on _

_Documentation on _

_Documentation on _

_Documentation on _

_Documentation on _

_Documentation on _

_Documentation on _

_Documentation on _

_Documentation on _

_Documentation on _

MDN
MDN
MDN
MDN
MDN
this article
MDN
MDN
MDN
MDN
MDN
MDN
MDN
MDN
MDN
MDN
MDN
๐Ÿ‘ฝ
๐Ÿ
Page cover image