I have a piece of JavaScript code using a for loop to reverse a string. However, I would like to know if it is possible to use a for in loop instead and how would I go about that?
function reverse(str){
var reversedString = '';
for (var i = str.length - 1; i >= 0; i--){
reversedString = reversedString + str[i];
}
return reversedString;
}
alert(reverse('hello'));
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…