Explore Arrays
Arrays
Let's explore arrays!
Explore:
- Print out 'snow' from
firstArray
. - Add and take out items from
firstArray
usingpush()
andpop()
. - Write your own array and access and manipulate the values.
// Let's set up our first arraylet firstArray = ['ceramics', 5, true,'snow', 'mango']//Now let's see our array and our array itemsconsole.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.lengthconsole.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 arrayconsole.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);