0

How do i reverse a string in Javascript with for loops?

Could you please help with detailed explanation. Or if you could guide me step by step. I do not just get it.

27th Sep 2017, 5:07 PM
Ifunanya
Ifunanya - avatar
2 Respostas
+ 4
One possibility is : - You put your String inside a variable. - You check the size of your text with 'length', by size I mean the number of characters inside your text including visible, invisible characters. - You split the String into an array. Each character of your String will be inside an individual "space" of the array => array( "M", "y", " ", "w", "o", "r", "d" ) - By using a 'For' loop the idea is to loop one time / character inside you text, if your text is "test" it should loop 4 times. - The next idea is to feel a new variable with the array. by starting from the last character to the first one. When it's done you should be able to log your word reversed. Tips : for( var i = array.length; i > 0; i--)
27th Sep 2017, 7:07 PM
Geoffrey L
Geoffrey L - avatar
0
Thank you, Geoffrey!
29th Sep 2017, 3:50 PM
Ifunanya
Ifunanya - avatar