DEV Community

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

Posted on

1 1

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

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay