Home arrow JavaScript arrow Page 2 - More on JavaScript Array Objects
JAVASCRIPT

More on JavaScript Array Objects


Thanks for dropping by for another episode of our series on JavaScript Array Objects. We left off discussing five of the thirteen array objects JavaScript has to offer. Here, in this issue, we will make an effort to cover the remaining eight.

Author Info:
By: James Payne
Rating: 5 stars5 stars5 stars5 stars5 stars / 3
December 16, 2008
TABLE OF CONTENTS:
  1. · More on JavaScript Array Objects
  2. · Shift() It Around
  3. · Slice Them Taters
  4. · Sort() It Out
  5. · Fixing the Issue

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
More on JavaScript Array Objects - Shift() It Around
(Page 2 of 5 )

As stated in our beautiful table above, the shift() object is used to remove the first or left-most element in a given array, and return it. Below, we use it in a program that lists a bunch of fat guys, one of whom dies, and must be removed from the list: 

<html>

<body>

<script type="text/javascript">

var fat = new Array(4);

fat[0] = "John Candy";

fat[1] = "Me";

fat[2] = "Valerie Bertinelli";

document.write("Here is a list of fat guys:");

document.write("<br />" + "<br />");

document.write(fat + "<br />" + "<br />");

document.write("This one died:" + "<br />");

document.write(fat.shift() + "<br />" + "<br />");

document.write("Leaving these:" + "<br />");

document.write(fat);

</script>

</body>

</html>

As you can see, John Candy has been removed from the array, resulting in this:

  Here is a list of fat guys:

  John Candy,Me,Valerie Bertinelli,

  This one died:
  John Candy

  This one lost weight:
  Me

  Leaving these:
  Valerie Bertinelli,

If I somehow miraculously lost all of my weight, we could also remove me from the list:


<html>

<body>

<script type="text/javascript">

var fat = new Array(4);

fat[0] = "John Candy";

fat[1] = "Me";

fat[2] = "Valerie Bertinelli";

document.write("Here is a list of fat guys:");

document.write("<br />" + "<br />");

document.write(fat + "<br />" + "<br />");

document.write("This one died:" + "<br />");

document.write(fat.shift() + "<br />" + "<br />");

document.write("This one lost weight:" + "<br />");

document.write(fat.shift() + "<br />" + "<br />");

document.write("Leaving these:" + "<br />");

document.write(fat);

</script>

</body>

</html>

Which results in:

  Here is a list of fat guys:

  John Candy,Me,Valerie Bertinelli,

  This one died:
  John Candy

  This one lost weight:
  Me

  Leaving these:
  Valerie Bertinelli,


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