23.04.2013 Views

javascript

javascript

javascript

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

[2002, 72, 89],<br />

[2001, 62, 100],<br />

[2000, 69, 93],<br />

[1999, 78, 83],<br />

[1998, 69, 93],<br />

[1997, 79, 83],<br />

[1996, 73, 89],<br />

[1995, 58, 86],<br />

[1994, 53, 61],<br />

[1993, 75, 87]];<br />

console.dir(pirates.shift());<br />

Figure 6–24. shift() removes and returns the first element in an array.<br />

CHAPTER 6 ■ FUNCTIONS AND ARRAYS<br />

Note that shift() modifies pirates, too, by shifting the contents down one place in the array every<br />

time it is invoked. This means that element 0 is removed, element 1 becomes element 0, and so on. So,<br />

after invoking shift() three times in a row, pirates has just 15 elements rather than 18 as Figure 6–25<br />

displays.<br />

var pirates = [[2010, 57, 105],<br />

[2009, 62, 99],<br />

[2008, 67, 95],<br />

[2007, 68, 94],<br />

[2006, 67, 95],<br />

[2005, 67, 95],<br />

[2004, 72, 89],<br />

[2003, 75, 87],<br />

[2002, 72, 89],<br />

[2001, 62, 100],<br />

[2000, 69, 93],<br />

[1999, 78, 83],<br />

7<br />

231

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!