-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrays.js
More file actions
66 lines (57 loc) · 1.43 KB
/
Copy pathArrays.js
File metadata and controls
66 lines (57 loc) · 1.43 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// arrays are used to store data of same data type at a single place
let cars = ["bmw" , "honda" , "toyota"];
console.log(cars[0]);
// prints bwm
// now how to add in the arrays
//push
let cars = ["bmw" , "honda" , "toyota"];
console.log(cars[0]);
cars.push("alfa romeo");
// added at the end
// Removing from the array
//pop
let cars = ["bmw" , "honda" , "toyota"];
console.log(cars[0]);
cars.pop();
// last will be removed
// adding at the start
let cars = ["bmw" , "honda" , "toyota"];
console.log(cars[0]);
cars.unshift("Suzuki");
// removing from the start
let cars = ["bmw" , "honda" , "toyota"];
console.log(cars[0]);
cars.shift("Suzuki");
// length of array
// removing from the start
let cars = ["bmw" , "honda" , "toyota"];
console.log(cars[0]);
console.log(cars.length);
// for loop of array
let cars = ["bmw" , "honda" , "toyota"];
console.log(cars[0]);
for (let i=0 ; i = cars.length ; i++){
console.log(cars[i]);
}
// for...of loop of array
let cars = ["bmw" , "honda" , "toyota"];
console.log(cars[0]);
for (const car of cars){
console.log(car);
}
// multiple objects can be stored in array also just by changning the brackets at the start
const student = [
{
name : "Afaq",
age : 21,
gender : "Male",
Height : "5,4",
marks : {
phy : 34,
math : 40,
SE : 88
},
}];
// annd for accessign it
console(student[0].name);
//this will gives the marks of SE of student at the 0 index of arrays