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.

Figure 1–14. Objects may have elements, too.<br />

CHAPTER 1 ■ REPRESENTING DATA WITH VALUES<br />

In Chapter 5, we’ll explore some array-only features for manipulating elements. Those make<br />

elements in array magical compared to those in an object. It’s sort of like how putting on the spidey suit<br />

turns ordinary Peter Parker into Spiderman.<br />

Creating a Function Literal<br />

Alright, it’s trivial to query our ice cream array for what flavor I’d rank eighth:<br />

var iceCream = [<br />

"Chocolate Fudge Brownie",<br />

"Half Baked",<br />

"New York Super Fudge Chunk",<br />

"Coffee Heath Bar Crunch",<br />

"Cherry Garcia",<br />

"Mud Pie",<br />

"Milk & Cookies",<br />

"Cinnamon Buns",<br />

"Chocolate Chip Cookie Dough",<br />

"Mission to Marzipan"<br />

];<br />

iceCream[7];<br />

// "Cinnamon Buns"<br />

But it’s quite another to query whether a flavor like "Cinnamon Buns" is among my top ten, as the<br />

following sample and Figure 1–15 illustrate:<br />

var iceCream = [<br />

"Chocolate Fudge Brownie",<br />

"Half Baked",<br />

"New York Super Fudge Chunk",<br />

"Coffee Heath Bar Crunch",<br />

"Cherry Garcia",<br />

19

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

Saved successfully!

Ooh no, something went wrong!