-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrays.js
More file actions
26 lines (22 loc) · 787 Bytes
/
arrays.js
File metadata and controls
26 lines (22 loc) · 787 Bytes
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
//Syntax
var train =["wheat","barley","salt","potatoes","rock"];
console.log(train);
console.log(train[2]);
//In JavaScript, arrays are objects. That means that arrays also have some built-in properties and methods. One of the most commonly used built-in methods on arrays are the push() and the pop() methods.
//To add new items to an array, I can use the push() method:eg;
var fruits =[];
fruits.push("apple");
fruits.push("mango");
console.log(fruits);
//To remove the last item from an array, I can use the pop() method:eg;
fruits.pop("mango");
console.log(fruits);
//
function arrayBuilder(one, two, three) {
var arr = [];
arr.push(one);
arr.push(two);
arr.push(three);
console.log(arr);
}
arrayBuilder('apple', 'pear', 'plum'); // ['apple', 'pear', 'plum']