forked from benlcollins/introductionToAppsScript
-
Notifications
You must be signed in to change notification settings - Fork 1
/
010_IntroToAppsScript_Arrays.js
73 lines (48 loc) · 1.55 KB
/
010_IntroToAppsScript_Arrays.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
function arrayFunction() {
// create new array like this
const newArray = [];
// ordering of items is important
const fruitsArray = ['Apple','Banana','Pear','Strawberry'];
//console.log(fruitsArray); // [Apple, Banana, Pear, Strawberry]
// array index starts at 0
// access items in array with this notation:
//console.log(fruitsArray[0]); // Apple
//console.log(fruitsArray[1]); // Banana
//console.log(fruitsArray[2]); // Pear
//console.log(fruitsArray[3]); // Strawberry
//console.log(fruitsArray[4]); // undefined, nothing at position 4
// can also write arrays like this:
const anotherArray = ["first",
"second",
"third",
"fourth"];
//console.log(anotherArray);
/*
Array Methods
*/
const countingArray = ['two','three','four'];
console.log("Starting array:");
console.log(countingArray);
// add item to array
// add to end
countingArray.push('one hundred');
console.log(countingArray);
// add to start
countingArray.unshift('one');
console.log(countingArray);
// add to middle
countingArray.splice(2,0,'miss a few');
console.log(countingArray);
countingArray.splice(3,0,'ninety nine');
console.log(countingArray);
// removing items from array
// remove from end
//countingArray.pop();
//console.log(countingArray);
// remove from beginning
//countingArray.shift();
//console.log(countingArray);
// remove from middle
countingArray.splice(4,2);
console.log(countingArray);
}