DEV Community

Cover image for JavaScript Array Methods Cheat Sheet
Hidayt Rahman
Hidayt Rahman

Posted on

JavaScript Array Methods Cheat Sheet

Top popular JavaScript array methods.

concat()

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

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

join()

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

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

slice()

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

// Output: ["😩"]
Enter fullscreen mode Exit fullscreen mode

indexOf()

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

// Output: 1
Enter fullscreen mode Exit fullscreen mode

lastIndexOf()

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

// Output: 2
Enter fullscreen mode Exit fullscreen mode

reverse()

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

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

sort()

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

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

shift()

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

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

unshift()

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

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

pop()

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

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

push()

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

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

filter()

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

// Output: ["πŸ‘¨"]
Enter fullscreen mode Exit fullscreen mode

includes()

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

// Output: true
Enter fullscreen mode Exit fullscreen mode

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()

Top comments (0)