Articles by @sakethk

Articles by @sakethk

Learn Javascript array methods with the help of emojis

Listen to this article

//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() = [ 'πŸ˜„', '😊', 'πŸ™‚', '😑', '🀬' ]
Β 
Share this