-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray.js
More file actions
51 lines (36 loc) · 1.24 KB
/
Array.js
File metadata and controls
51 lines (36 loc) · 1.24 KB
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
/*var cars = [
"Saab",
"Volvo",
"BMW"
];
cars.pop();
cars.pop();
console.log(cars);*/
/*var cars = new Array("Saab", "Volvo", "BMW");
var x = cars.length; // The length property returns the number of elements in cars
var y = cars.sort();
console.log(x);
console.log(y); // The sort() method sort cars in alphabetical order
cars.push("Maruthi")*/
/*var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Lemon");
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits[fruits.length] = "Lemon"; // adds a new element (Lemon) to fruits*/
/*var index,text=0;
var fruits = ["Banana", "Orange", "Apple", "Mango"];
for (index = 0; index < fruits.length; index++) {
text += fruits[index];
console.log(fruits[index]);
}*/
/*var points1 = new Array(20) // Bad
var points2 = [40, 100, 1, 5, 25, 10];
var num = 'a'; // Good
console.log(typeof points1);
console.log(typeof points2);
console.log(typeof num);
/*
var points = new Array(40, 100); // Creates an array with two elements (40 and 100)
var points = new Array(40); // Creates an array with 40 undefined elements !!!!!
var fruits = ["Banana", "Orange", "Apple", "Mango"];
typeof fruits; // typeof returns object
*/