How to reverse a String in JavaScript Tutorial

preview_player
Показать описание


Other videos in the JavaScript Snippets series:

Don’t forget to subscribe to the Junior Developer Central channel for more videos and tutorials!

Whilst it’s not the most common of tasks to do as a Junior Developer, finding out how to reverse a string in JavaScript is handy to know as it introduces you to a few new concepts in terms of handling arrays.

But wait!? A string isn’t an array!

In the tutorial you’ll learn how to do exactly this by using the split() function on the original string and then using the join() function to re-assemble it once it’s been reversed.

You’ll see that this process is very simply however sometimes you’ll be asked (perhaps at a job interview) how to reverse a string in JavaScript without using reverse method. In this instance, the interviewers are checking you can handle basic algorithmic challenges without relying on inbuilt functions.

So, in order to learn how to reverse a string in JavaScript without using reverse method, in the video we’ll discuss how to reverse a string in JavaScript with for loops. Whilst this isn’t the most elegant of ways to do it, it is fairly straightforward and it’s always good to know different ways of accomplishing the same task. Channel Handle @codebubb
Рекомендации по теме
Комментарии
Автор

Thanks for the help! I'm learning about loops at my studies now.

DanielGyldenløve
Автор

These kinds of videos should be showing the problem as a function. You would never get away with this at a job interview.

steven
Автор

It's amazing, I understand both the codes. Thank you, James!

uaplatformacomua
Автор

Exactly what I was looking for, with the for loop. Thank you :)

myrinaDM
Автор

Thank you, James, you helped me understand split(), joint, reverse() methods as I was strangling to underused it.

amdnour
Автор

Thanks. This tutorial explains everything very well.

annadueckthiessen
Автор

I love your style. But my question is how can you reverse only words with 6 or more letters in a given string. That is ''My second programs code'' turns to "My dnoces smargorp". Thank you

DeenTechIT
Автор

Problem 3

Write a JavaScript program that accepts two strings as user input. The program should determine the first occurrence of the second string within the first string. And then print into the console the second string along with the last remaining characters of the first string. Print the string in capital letters.

Sample Input:
“University”
“ver”


Sample output:
“VERSITY”

Problem 4

Write a JavaScript program that accepts a word as a user input, reverses it, and then print into the console the new word with the first letter capital.

Sample Input:
“Hawkeye”


Sample output:
“Eyekwah”

TheMarketingManU
visit shbcf.ru