How to add item to the beginning of an array in JavaScript

1 Answer

0 votes
const arr = ["javascript", "php", "c++", "python"];

arr.unshift("c#");

arr.forEach(function(item, index, array) {
  document.write(item + " " + index + "<br />");
});



/*
run:
      
c# 0
javascript 1
php 2
c++ 3
python 4
    
*/

 



answered Nov 2, 2019 by avibootz

Related questions

1 answer 131 views
1 answer 131 views
...