In this tutorial you’ll learn how to check if a string is a palindrome using JavaScript. Get my free 32 page eBook of JavaScript HowTos 👉 https://bit.ly/2ThXPL3
Don’t forget to subscribe to the Junior Developer Central channel for more videos and tutorials!
So there are a couple of ways to check is a string is a palindrome in JavaScript and we’ll first look at what seems to be the most logical way of doing it which is using a for loop.
In the tutorial i’ll take you through the process of looping through a string to check if each character at opposite ends of the string are the same.
This process is a pretty simple way to check a string (or number) is a palindrome or not in JavaScript however we’ll look at one problem with this which is if the string has unexpected spaces, commas or other symbols. By definition, as long as the actual letters match up (without any of the symbols) then the string is technically still a palindrome so we should accept it.
So we need a way to remove these characters that we don’t want to check for in our palindrome with JavaScript. You’ll learn a simple way to do this using a Regular Expression.
Once you’ve learnt a way to check for a palindrome using a for loop, we’ll look at some ways of doing it with the javascript reverse function and also a bit of a more esoteric method using a filter function to remove items from the array if they don’t match the end of the string.
Other videos in the JavaScript Snippets series:
Find the largest number in an array JavaScript Tutorial: • Find the largest number in an array J...
How to find the longest word in a String with JavaScript: • How to find the longest word in a Str...
How to reverse a String in JavaScript Tutorial: • How to reverse a String in JavaScript...
Javascript String Length: How to determine the size of a string: • Javascript String Length: How to dete...
JavaScript join method: How to merge arrays into one value: • JavaScript join method: How to merge ...
JavaScript How To Remove An Item From Array Tutorial: • JavaScript How To Remove An Item From...
Javascript How To Convert String To Number Tutorial: • Javascript How To Convert String To N...
JavaScript Create HTML Element: How to dynamically add tags to your pages: • JavaScript Create HTML Element: How t...
JavaScript String Contains: How to check a string exists in another: • JavaScript String Contains: How to ch...
Link JavaScript to HTML: How to run your JavaScript code in the browser: • Link JavaScript to HTML: How to run y...
JavaScript Copy Array: How to make an exact copy of an array in JavaScript: • JavaScript Copy Array: How to make an...
JavaScript Capitalize First Letter: How to make strings and arrays sentence case: • JavaScript Capitalize First Letter: H...
Javascript Print To Console Tutorial: Different ways to output data to the console: • Javascript Print To Console Tutorial:... Channel Handle @codebubb