JavaScript Array Methods Cheat Sheet

Top popular JavaScript array methods.

concat()

['πŸ˜‰', 'πŸ‘Š'].concat('😩')

// Output: (3)Β ["πŸ˜‰", "πŸ‘Š", "😩"]

join()

['πŸ‘¨β€πŸ¦³', 'πŸ‘©β€πŸ¦³'].join('πŸ’˜')

// Output: "πŸ‘¨β€πŸ¦³πŸ’˜πŸ‘©β€πŸ¦³"

slice()

["πŸ˜‰", "πŸ‘Š", "😩"].slice(2)

// Output: ["😩"]

indexOf()

["😜", "πŸ‘", "πŸ₯Ά"].indexOf('πŸ‘')

// Output: 1

lastIndexOf()

["😜", "πŸ‘", "πŸ‘"].lastIndexOf('πŸ‘')

// Output: 2

reverse()

["😜", "πŸ‘", "πŸ₯Ά"].reverse()

// Output: (3)Β ["πŸ₯Ά", "πŸ‘", "😜"]

sort()

["πŸ‘¨", "πŸ‘΄", "πŸ‘¦"].sort()

// Output: (3)Β ["πŸ‘¦", "πŸ‘¨", "πŸ‘΄"]

shift()

["πŸ‘¦", "πŸ‘¨", "πŸ‘΄"].shift()

// Output: (2)Β ["πŸ‘¨", "πŸ‘΄"]

unshift()

["πŸ‘¦", "πŸ‘¨", "πŸ‘΄"].unshift('πŸ‘©');

// Output: (4)Β ["πŸ‘©", "πŸ‘¦", "πŸ‘¨", "πŸ‘΄"]

pop()

["πŸ‘¦", "πŸ‘¨", "πŸ‘΄"].pop();

// Output: (2)Β ["πŸ‘¦", "πŸ‘¨"]

push()

["πŸ‘¦", "πŸ‘¨", "πŸ‘΄"].push('πŸ”₯');

// Output: (4)Β ["πŸ‘¦", "πŸ‘¨", "πŸ‘΄", "πŸ”₯"]

filter()

["πŸ‘¦", "πŸ‘¨", "πŸ‘΄"].filter(person => person == 'πŸ‘¨')

// Output: ["πŸ‘¨"]

includes()

["πŸ‘¦", "πŸ‘¨", "πŸ‘΄"].includes('πŸ‘¦')

// Output: true

Hope this will help you to mess with array.

You can suggest if I missed any thing. Also share suggestion for any other cheat sheet.

Happy.Code()

27