Reverse a string in javascript without using any inbuilt function -
function reverse1(str){ var = ""; for(var = 0; <= str.length/2; i++){ = str[i]; str[i] = str[str.length-i-1]; str[str.length-i-1] = a; } return str; } var str = "abcdef"; reverse1(str);
i want reverse string without using inbuilt function, , want change original string doesn't work well. language javascript.
create new string , add chars original string backwards:
function reverse1(str){ var r = ""; for(var = str.length - 1; >= 0; i--){ r += str.charat(i); } return r; }
then say:
str = reverse1(str);
Comments
Post a Comment