How to use forEach() to print an array in reverse order in JavaScript

1 Answer

0 votes
const array = ['c++', 'javascript', 'c', 'java'];
  
array
  .slice()
  .reverse()
  .forEach(element => {
    	console.log(element); 
  });  
  
  
  
  
  
/*
run:
  
"java"
"c"
"javascript"
"c++"
  
*/

 



answered May 17, 2022 by avibootz

Related questions

1 answer 127 views
2 answers 217 views
1 answer 98 views
1 answer 125 views
1 answer 172 views
...