Languages
[Edit]
EN

JavaScript - split array into two based on index

0 points
Created by:
Kevin
797

In this article, we would like to show you how to split array into two based on index in JavaScript.

Practical examples

Edit

1. Including index

Edit

In this example, we use slice() method to split array into two parts. The first part contains elements from index 0 to the specified index (included), and the second part contains the rest of the array.

2. Excluding index

Edit

In this example, we use slice() method to split array into two parts. The first part contains elements from index 0 to the specified index (excluded), and the second part contains the rest of the array.

 

See also

Edit
  1. JavaScript - truncate array

  2. JavaScript - get subarray from array

  3. JavaScript - split array into chunks

References

Edit
  1. Array.prototype.slice() - JavaScript | MDN
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join