Reverse of string using split and join

by SriSri M

JavaScript

// Reverse of string using split and join array

function revStr(str) {
//debugger;
	var getstr = str;
  var splitStr = getstr.split("");
  var reverseStr = splitStr.reverse();
  var joinStr = reverseStr.join("");
  //console.log(joinStr);
  return joinStr;
 
}

revStr("hello");

//Decrementing for-loop with concatenation

function reverse(str) {
//debugger;
	var newStr = "";
  for(i = str.length-1; i >= 0; i--) {
  newStr += str[i];
  console.log(newStr);
  }
}
reverse("hey");