Javascript Array Example - Test for Palindrom
Here are some simple example of javascript. We will try to find if a string is palindrom. A palindrome is a sequence that may be read the same way in either direction - example 1234321 or abcdcba.
Take a look at the following example
<html> <body> <script type="text/javascript"> <!-- /* ******************************************************** Example - Test if a string is a palindrom ******************************************************** */ var x ="12321"; // string to test for palindrome var y = x.split(''); var z =[]; var match = true; for (i=0; i<=(y.length-1); i++) { z[i]= y[i]; } y.reverse(); for (i=0; i<=(y.length-1); i++) { if (z[i] != y[i]) match = false; } if (match) document.writeln (x + ' is a palindrome'); else document.writeln (x + ' is a not a palindrome'); //--> </script> </body> </html> |
Try this example online here .