Learn Javascript array methods with the help of emojis

ยท

1 min read


//Concat
['๐Ÿ‹๐Ÿปโ€โ™‚๏ธ', '๐Ÿƒ๐Ÿป'].concat('๐Ÿง˜๐Ÿป') = [ '๐Ÿ‹๐Ÿปโ€โ™‚๏ธ', '๐Ÿƒ๐Ÿป', '๐Ÿง˜๐Ÿป' ] 

//Join
['๐Ÿคด๐Ÿป', '๐Ÿ‘ธ๐Ÿป'].join('๐Ÿ’') = '๐Ÿคด๐Ÿป๐Ÿ’๐Ÿ‘ธ๐Ÿป'

//Slice
['๐Ÿ˜ญ', '๐Ÿ˜ถ', '๐Ÿ˜€'].slice(2)= [ '๐Ÿ˜€' ]

//Index of
['0๏ธโƒฃ', '1๏ธโƒฃ', '2๏ธโƒฃ', '3๏ธโƒฃ'].indexOf('1๏ธโƒฃ') = 1

//Includes
['0๏ธโƒฃ', '1๏ธโƒฃ', '2๏ธโƒฃ', '3๏ธโƒฃ'].includes('1๏ธโƒฃ') = true

//Every
[
  {label: '0๏ธโƒฃ', type: 'emoji'}, 
  {label: '1๏ธโƒฃ', type: 'emoji'}, 
  {label: '2๏ธโƒฃ', type: 'emoji'}, 
  {label: '3๏ธโƒฃ', type: 'emoji'}
].every(item => item.type === 'emoji') = true

//Some
[0, '1๏ธโƒฃ', '2๏ธโƒฃ', '3๏ธโƒฃ'].some(item => typeof item === 'number') = true

//Fill
['๐Ÿ˜€', '๐Ÿ˜ƒ', '๐Ÿ˜„'].fill('๐Ÿคช') = [ '๐Ÿคช', '๐Ÿคช', '๐Ÿคช' ]

// Map
['0๏ธโƒฃ', '1๏ธโƒฃ', '2๏ธโƒฃ', '3๏ธโƒฃ'].map((item, index) => item + " -> " + index) = [ '0๏ธโƒฃ -> 0', '1๏ธโƒฃ -> 1', '2๏ธโƒฃ -> 2', '3๏ธโƒฃ -> 3' ]

// Map
['0๏ธโƒฃ', '1๏ธโƒฃ', '2๏ธโƒฃ', '3๏ธโƒฃ'].filter((item, index) => index === 1) = [ '1๏ธโƒฃ' ]

//Reduce
['0๏ธโƒฃ', '1๏ธโƒฃ', '2๏ธโƒฃ', '3๏ธโƒฃ'].reduce((acc, current) => acc + current) = '0๏ธโƒฃ1๏ธโƒฃ2๏ธโƒฃ3๏ธโƒฃ'

//Push
['๐Ÿคฌ', '๐Ÿ˜ก', '๐Ÿ™‚', '๐Ÿ˜Š'].push('๐Ÿ˜„') = 5 // it will insert '๐Ÿ˜„' to list at last

//unshift
['๐Ÿ˜ก', '๐Ÿ™‚', '๐Ÿ˜Š', '๐Ÿ˜„'].unshift('๐Ÿคฌ') = 5 // it will insert '๐Ÿคฌ' to list at first

//Pop
['๐Ÿคฌ', '๐Ÿ˜ก', '๐Ÿ™‚', '๐Ÿ˜Š', '๐Ÿ˜„'].pop('๐Ÿ˜„') = '๐Ÿ˜„' // it will remove '๐Ÿ˜„' from list

//Shift
['๐Ÿคฌ', '๐Ÿ˜ก', '๐Ÿ™‚', '๐Ÿ˜Š', '๐Ÿ˜„'].shift() = '๐Ÿคฌ' // it will remove '๐Ÿคฌ' from list

//Reverse
['๐Ÿคฌ', '๐Ÿ˜ก', '๐Ÿ™‚', '๐Ÿ˜Š', '๐Ÿ˜„'].reverse() = [ '๐Ÿ˜„', '๐Ÿ˜Š', '๐Ÿ™‚', '๐Ÿ˜ก', '๐Ÿคฌ' ]
ย