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

Image of Timescale

๐Ÿš€ pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applicationsโ€”without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post โ†’

Top comments (0)

Image of Docusign

๐Ÿ› ๏ธ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more