Explore Arrays

Arrays

Let's explore arrays!

Explore:

  1. Print out 'snow' from firstArray.
  2. Add and take out items from firstArray using push() and pop().
  3. Write your own array and access and manipulate the values.
// Let's set up our first array
let firstArray = ['ceramics', 5, true,'snow', 'mango']
//Now let's see our array and our array items
console.log(firstArray);
// We can get an item of the array by putting the index in brackets.
// Notice that arrays are zero-indexed so the first item is item 0.
console.log(firstArray[0]);
// We can find the length of the array by using yourArraysName.length
console.log(firstArray.length);
// Note that yourArraysName.length-1 is the index of the last item.
console.log(firstArray.length-1);
console.log(firstArray[firstArray.length-1]);
// Now let's change the array.
// Let's reverse the order of the array
console.log(firstArray);
firstArray.reverse();
console.log(firstArray);
// Here we add to the array.
firstArray.push('salsa dancing');
console.log(firstArray);
// Here we take items off of the array.
firstArray.pop();
console.log(firstArray);
firstArray.pop();
console.log(firstArray);