How to remove N elements from array start from negative index forward in Node.js

1 Answer

0 votes
const arr = ['node.js', 'php', 'python', 'c', 'c#', 'c++', 'go', 'css', 'java', 'python'];
   
const index = -3;
const N = 2
  
arr.splice(index, N);
   
console.log(arr); 
   
   
   
   
/*
run:

[
  'node.js', 'php',
  'python',  'c',
  'c#',      'c++',
  'go',      'python'
]
   
*/

 



answered Jul 7, 2022 by avibootz
...