1var array = [item1, item2, .....];
2/*
3
4 item1 and item2 could be a string (which is
5 a letter written in double or single quotes like this "string" or 'string') or
6 a number (which is just a normal number on the keypad) or a boolean (which is
7 an experssion which either returns to true of false) and the ..... means that
8 the inputs can be infinite.
9
10*/
1//Creating a list
2var fruits = ["Apple", "Banana", "Cherry"];
3
4//Creating an empty list
5var books = [];
6
7//Getting element of list
8//Lists are ordered using indexes
9//The first element in an list has an index of 0,
10//the second an index of 1,
11//the third an index of 2,
12//and so on.
13console.log(fruits[0]) //This prints the first element
14//in the list fruits, which in this case is "Apple"
15
16//Adding to lists
17fruits.push("Orange") //This will add orange to the end of the list "fruits"
18fruits[1]="Blueberry" //The second element will be changed to Blueberry
19
20//Removing from lists
21fruits.splice(0, 1) //This will remove the first element,
22//in this case Apple, from the list
23fruits.splice(0, 2) //Will remove first and second element
24//Splice goes from index of first argument to index of second argument (excluding second argument)
1//create an array like so:
2var colors = ["red","blue","green"];
3
4//you can loop through an array like this:
5for (var i = 0; i < colors.length; i++) {
6 console.log(colors[i]);
7}
1// Don't need to provide elements directly, but you can
2
3// FIRST OPTION
4var myArray = new Array(/*elements1, elements2*/);
5
6// SECOND OPTION
7var mySecondArray = [/*element1, element2*/];