Q:

Write a JavaScript program to remove specified elements from the right of a given array of elements

0

Write a JavaScript program to remove specified elements from the right of a given array of elements.

All Answers

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

function remove_from_right(arr, n = -1){
  return arr.slice(n); 
}

console.log(remove_from_right([1, 2, 3]));
console.log(remove_from_right([1, 2, 3], -1));
console.log(remove_from_right([1, 2, 3], -2));
console.log(remove_from_right([1, 2, 3], -4));

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