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)