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

1 Answer

0 votes
let arr:string[] = ["c++", "typescript", "php", "python", "go", "c"];
   
let shifted = arr.shift();
console.log(arr);
console.log(shifted);
   
shifted = arr.shift();
console.log(arr);
console.log(shifted);
 

 
   
/*
run:
        
["typescript", "php", "python", "go", "c"] 
"c++" 
["php", "python", "go", "c"] 
"typescript" 
           
*/
 
   

 



answered Aug 12, 2022 by avibootz
...