Java Reference
In-Depth Information
The unshift() method is similar to the push() method, but this appends a new item
to the beginning of the array. This is the equivalent of Donatello adding a new pizza box to
the bottom of the pile, as shown in Figure 3.6 :
pizzas.unshift("Chicken & Bacon");
<< 3
Figure 3.6. Using unshift() on our array
Merging Arrays
The concat() method can be used to merge an array with one or more arrays:
pizzas.concat(["Spicy Beef", "Chicken and Mushroom"]);
<< ["Chicken & Bacon", "Mushroom", "Pepperoni","Spicy
Beef",
"Chicken and Mushroom"]
Note that this does not change the pizzas array, it simply creates another array combining
the two arrays. You can use assignment to change the pizzas array to this new array. This
would be like Donatello adding a whole new pile of boxes on top of the pile he already has:
pizzas = pizzas.concat(["Spicy Beef", "Chicken and
Mushroom"]);
<< ["Chicken & Bacon", "Mushroom", "Pepperoni","Spicy
Search WWH ::




Custom Search