How to print array in JavaScript

3 Answers

0 votes
const arr = ["javascript", "php", "c++", "python"];
 
arr.forEach(function(item, index, array) {
   console.log(item + " " + index);
});
 



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

 



answered Jun 11, 2021 by avibootz
0 votes
const arr = ["javascript", "php", "c++", "python"];
 
console.log(arr);
 



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

 



answered Jun 11, 2021 by avibootz
0 votes
const arr = ["javascript", "php", "c++", "python"];
 
for(let i = 0; i < arr.length; i++) {
  console.log(arr[i]);
}
 



 
/*
run:
       
"javascript"
"php"
"c++"
"python"
     
*/

 



answered Jun 11, 2021 by avibootz
edited Aug 2, 2021 by avibootz
...