How to remove and return the first element of array in Node.js

1 Answer

0 votes
let arr = ["c++", "nodejs", "php", "python", "go"];
   
let shifted = arr.shift();
console.log(arr);
console.log(shifted);
   
shifted = arr.shift();
console.log(arr);
console.log(shifted);
 
 
 
 
   
/*
run:
        
[ 'nodejs', 'php', 'python', 'go' ]
c++
[ 'php', 'python', 'go' ]
nodejs
           
*/

 



answered Aug 12, 2022 by avibootz
...