working with arrays

by james gotsell

HTML

<script src=" https://getfirebug.com/firebug-lite-debug.js"></script>

JavaScript

var fruits = ["apple", "banana", "mango"]

console.log(fruits.length)

/// add to the front of the array 

var newLength = fruits.unshift("watermelon")

console.log(newLength)
/// new length after adding watermelon to the array

fruits.push("plum");

console.log(fruits)
// new length of fruits aftyer pushing lpum into the array
console.log(fruits.length)

// find index of an item in a array 

var pos = fruits.indexOf("banana")
console.log(pos)
var pos2 = fruits.indexOf("watermelon")
console.log(pos2)

// copy an array 

var shallowCopy = fruits.slice();

console.log(shallowCopy + " " + "copy of fruits array");