How to add (append) item to the end of an array in JavaScript

1 Answer

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

arr.push('c#');

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



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

 



answered Nov 2, 2019 by avibootz

Related questions

1 answer 179 views
2 answers 186 views
1 answer 187 views
3 answers 228 views
1 answer 149 views
...