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 189 views
2 answers 199 views
1 answer 201 views
3 answers 243 views
1 answer 159 views
...