1some_array = ["John", "Sally"];
2some_array.push("Mike");
3
4console.log(some_array); //output will be =>
5["John", "Sally", "Mike"]
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// Making an array:
2const colors = ["red", "orange", "yellow"];
3
4// Arrays are indexed like strings:
5colors[0]; // "red"
6
7// They have a length:
8colors.length; //3
9
10// Important array methods:
11//push(value) - adds value to the END of an array
12//pop() - removes and returns last value in array
13
14//unshift(val) - adds value to START of an array
15//shift() - removes and returns first element in an array
1// A javascript array is a list of elements in one variable.
2
3//make an array like this:
4var array = ["Nothing", "Something", 510, "anything"]
5
6//You can log how many elements are in the array:
7console.log(array.length);
8
9// You can log a ["With your text and numbers in here"]:
10console.log(array)
11
12//you can also loop through an array like this:
13for (var i = 0; i < array.length; i++) {
14 console.log(array[i]);
15}
16// "pop" will remove the last element from the array
17var poppedarray = array.pop()
18// Will output: ["Nothing", "Something", 510].
19
20var pushedarray = array.push("anything");
21// Now back to the original!
22
23// now get the position of an element and their name:
24fruits.forEach(function(item, index, array) {
25 console.log(item, index);
26});
27// Nothing 0
28// Something 1
29// 510 2
30// Anything 3
31
32