SQL PHP HTML ASP JavaScript articles and free scripts to download

String reversal using charat and length property

We can reverse a string by using charat and length property of string functions in JavaScript. By using length property we will find out the total length of the string and then we will use one for loop we will print one by one character from last point using charat function.

Here is the code

<script type="text/javascript">

var my_str="Welcome to www.plus2net.com"

var i=my_str.length;
i=i-1;

for (var x = i; x >=0; x--)
{
document.write(my_str.charAt(x));

}

</script>


Google+

Jim25-04-2010
document.write(my_str.split('').reverse().join(''));
david bandel26-04-2010
note. the reason it's best to use str.charAt(x) rather than str[x] is that internet explorer doesn't support accessing characters of a string with array notation.
esso15-04-2014
this code but with Array ...???
esso15-04-2014
Write a JavaScript code that asks the user to enter a sentence in lowercase and it will display it in UPPERCASE. For example the user enters the sentence "javascript is beautiful", and the program displays "JAVASCRIPT IS BEAUTIFUL". (Use Arrays) solution !!!??....
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked




Join Our Email List
Email:  
For Email Newsletters you can trust
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer