How to print array values with indexes in JavaScript

2 Answers

0 votes
const arr = ['php', 'c++', 'c#', 'javascript'];
 
for (let i = 0; i < arr.length; i++) {
    document.write(`${i} ${arr[i]}` + '<br />');
}
 
  
  
/*
run:
        
0 php
1 c++
2 c#
3 javascript
      
*/

 



answered Nov 5, 2019 by avibootz
0 votes
const arr = ['php', 'c++', 'c#', 'javascript'];

for (let i = 0; i < arr.length; i++) {
    document.write(i + " " + arr[i] + '<br />');
}

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

 



answered Nov 5, 2019 by avibootz

Related questions

1 answer 290 views
1 answer 223 views
1 answer 224 views
1 answer 298 views
...