Reversing a string using for loop in JavaScript

We are required to write a JavaScript function that takes in a string as the only argument. The function should construct a new reversed string based on the input string using the for a loop.


Following is the code −

const str = 'this is the original string';
const reverseString = (str = '') => {
   let reverse = '';
   const { length: len } = str;
   for(let i = len - 1; i >= 0; i--){
      reverse += str[i];
   return reverse;


Following is the output on console −

gnirts lanigiro eht si siht

Updated on: 11-Dec-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started