How to remove and return the first element of array in JavaScript

1 Answer

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

 



answered Aug 30, 2020 by avibootz
edited Aug 12, 2022 by avibootz
...