• Post author:
  • Post category:Blog
  • Reading time:2 mins read
  • Post last modified:June 12, 2024

If we want to display all the elements of the days array in reverse order (starting from the last element) then we can do this using the statement:

  • for(let i = days.length - 1; i > 0; i--)
         console.log(days[i]);
  • for(let i = days.length; i > 0; i--)
         console.log(days[i]);
  • for(let i = days.length; i > 0; i--)
         console.log(i);
  • for(let i = days.length - 1; i >= 0; i--)
         console.log(days[i]);
Explanation & Hint:

for loop is used to iterate over the elements of the days array in reverse order. The loop starts from the index of the last element (days.length – 1) and decrements the index (i) by 1 in each iteration until it reaches 0. Inside the loop, console.log(days[i]) is used to display each element of the array. By iterating in reverse order, you can effectively display all the elements of the days array starting from the last element and going towards the first element.

For more Questions and Answers:

JavaScipt Essentials 1 (JSE) | JSE1 – Module 4 Test Exam Answers Full 100%

Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments