[JavaScript] Copy part of an array

Created on November 30, 2026

Use slice() with a starting index and an exclusive ending index. Here, slice(1, 3) copies the elements at indices 1 and 2.

arr = [
  'hello',
  'world',
  'good',
  'bye'
]

slicedArray = arr.slice(1, 3)

console.log(slicedArray)
[ 'world', 'good' ]
JavaScript