Arrays
array.js
food = ["sushi","pizza","tacos"];alert(food[1]);
push.js
food = ["sushi","pizza","tacos"];food.push("vegetable soup"); //adds to the arrayalert("You have " + food.length + " total food(s):\n" + food);
firstOrLast.js
food = ["sushi","pizza","tacos", "vegetable soup"];first = food.shift();second = food.shift();last = food.pop();alert(first); //sushialert(second); //pizzaalert(last); //vegetable soupalert(food); //tacos (the only food remaining)
There are many more array methods available in JavaScript that have not been covered here. Try and experiment with some of these methods:
- unshifting
- splicing
- slicing
- sorting or reversing - as shown here