subarray in javascript code example
Example 1: js subarray
let subArray = array.slice(startIndex, endIndex)
Example 2: javascript get sub array
var fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
var citrus = fruits.slice(1, 3);
Example 3: slice method in js
const FRUITS = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
var citrus = FRUITS.slice(1, 3);
var fromTheEnd = FRUITS.slice(-3, -1);
Example 4: javascript how to get subarray
const ar = [1, 2, 3, 4, 5];
const ar2 = ar.slice(1, 3 + 1);
console.log(ar2);