Get first 10 elements of an array in JavaScript | Example code

How to get the first 10 elements of an array in JavaScript?

To get the first n elements of an array, use JS slice method.

A complete example of a JavaScript Array gets the first 10 items:- Passing the index value in slice method 0 and 10.

Note: Array index start from 0.

Output:

Get first 10 elements of an array in JavaScript

Do comment if you have any questions and suggestions on this topic.

Note: The All JS Examples codes are tested on the Safari browser (Version 12.0.2) and Chrome.
OS: macOS 10.14 Mojave
Code: HTML 5 Version


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.