Home arrow JavaScript arrow Page 4 - JavaScript Objects: Finishing Strings
JAVASCRIPT

JavaScript Objects: Finishing Strings


In the last tutorial we continued our discussion on String Objects in JavaScript. Hopefully we will wrap it up in this episode. We left off with the Match() method, which allowed us to search a string and return the same string if it was present in our variable, or return a null value if it was not. We will pick back up with the Replace() method.

Author Info:
By: James Payne
Rating: 5 stars5 stars5 stars5 stars5 stars / 3
January 28, 2008
TABLE OF CONTENTS:
  1. · JavaScript Objects: Finishing Strings
  2. · The Replace() Method
  3. · The Search() Method
  4. · The Slice() Method
  5. · The Strike(), Sub(), Small() and Sup() Methods
  6. · The ToLowerCase() and ToUpperCase Methods

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
JavaScript Objects: Finishing Strings - The Slice() Method
(Page 4 of 6 )

The Slice() method is used when you want to divide up a pizza into separate portions. It is also used when you wish to extract or slice a part of a string and return it to a new string.


<html>

<body>


<script type="text/javascript">


var castle="Castle Greyskull!"

document.write(castle.slice(6))

document.write("<br />")



</script>


</body>

</html>

This code finds the text in the sixth string and returns it, resulting in:

  Greyskull!

If we wanted to grab more than one value, we do it like this:


<html>

<body>


<script type="text/javascript">


var castle="Castle Greyskull!"

document.write(castle.slice(6))

document.write("<br />")

document.write(castle.slice(0,17))

document.write("<br />")

document.write(castle.slice(0,15))

</script>


</body>

</html>

This results in the following manner:

  Greyskull!
  Castle Greyskull!
  Castle Greyskul

You will note that in the last criteria, I used the value 15, and hence we only got part of the word Greyskull, or Greyskul.


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 7 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials