js slice an array code example
Example 1: javascript copy array
var oldColors=["red","green","blue"];
var newColors = oldColors.slice(); //make a clone/copy of oldColors
Example 2: javascript how to get subarray
const ar = [1, 2, 3, 4, 5];
// slice from 1..3 - add 1 as the end index is not included
const ar2 = ar.slice(1, 3 + 1);
console.log(ar2);