how to get subarray from array in javascript code example
Example 1: javascript get sub array
var fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
var citrus = fruits.slice(1, 3);
Example 2: slice method in js
const FRUITS = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
var citrus = FRUITS.slice(1, 3);
var fromTheEnd = FRUITS.slice(-3, -1);
Example 3: javascript how to get subarray
const ar = [1, 2, 3, 4, 5];
const ar2 = ar.slice(1, 3 + 1);
console.log(ar2);
Example 4: array index javascript show only first 2 elements
array.slice(0, n);