Q:

Write a JavaScript program to remove n elements from the end of a given array

0

Write a JavaScript program to remove n elements from the end of a given array.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

const takeRight = (arr, n = 1) => arr.slice(arr.length - n, arr.length);

console.log(takeRight([1, 2, 3], 2));
console.log(takeRight([1, 2, 3]));

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now