Welcome to the Tutorial Site!



Let's learn about arrays!


Here we will discuss a few simple things about arrays!

  1. What can be put into an array
  2. What can be done to the items in an array
  3. Using index numbers to reference an array item

An array is very useful because it can be used to create a list for many different applications! any type of data can be put into an array, and we use a number index system to acces them later. This index system starts at [0] which can be confusing at first, easy to remember!


                 var sampleArray = ['string data', true, 22];
                 
                     console.log([1]);
                 // the boolean true will be printed
                 
We can use things like.splice() to cut out sections of the array, and replace them, by using their index number as reference. This method returns a copy of the array that you've selected, while substituting the item selected, with the new ones specified. Using (index, howmany, item1...) as parameters, you can select the section of the array you want to be spliced into and the added array items to be returned. In this way, we can use the index numbers allowed us by the array, to better manipulate it for future usage! var arrayForSplice = ['Ice Cream', 'Taco Bell', 'Frozen Burrito', 'Coffee', 'Cashews'];

                 arrayForSplice.splice(2, 2, '7-Layer Burrito', 'Spicy Tostada');
                 // console.log(arrayForSplice) would now return:
                  ['Ice Cream', '7-Layer Burrito', 'Spice Tostada','Coffee', 'Cashews'];
                 

Here is a helpful link!