You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//hum ab chahte hain ki har element ko ek alag variable se access kare
10
+
11
+
let book = ["ADV. JS", 200, 150];
12
+
13
+
let name = book[0];
14
+
let pages = book[1];
15
+
let price = book[2];
16
+
console.log(name); //ADV. JS
17
+
console.log(pages); //200
18
+
console.log(price); //150
19
+
20
+
21
+
//isi ka ek shotcut h array destructing
22
+
let book = ["ADV. JS", 200, 150];
23
+
24
+
let [name, pages, price, publication] = book; //array destructor ko initialize karna mandatory h. agar array ka 10 value v hota to destuctring s aasani se kar sakte hain.
25
+
console.log(name); //ADV.JS
26
+
console.log(pages); //200
27
+
console.log(price); //150
28
+
console.log(publication); //undefined error nhi dega but agar variable ka value nhi rahe to undefined store kar dega. i.e publication blank rahega.
29
+
30
+
31
+
let book = ["ADV. JS", , 200, 150];
32
+
//hum bich m v blank kr sakte hain value
33
+
let [name, pages, price, publication] = book; // hum publication ko bich m v rakh sakte hain.
34
+
console.log(name); //ADV. JS
35
+
console.log(pages); //undefined bcs pages is blank
36
+
console.log(price); //200
37
+
console.log(publication); //150
38
+
39
+
40
+
//extra variable ka name dalenge but value nhi hoga toh wo undefined ho jaygea
41
+
42
+
43
+
44
+
//balnk/undefined value k liye ek default value v hota h.
45
+
let book = ["ADV. JS", 600, 200, 150];
46
+
let [name, pages = 500, price, publication] = book; //hum pages m default value string store is trh se karenge. pages="hii"
47
+
48
+
//console.log(pages); //default value 500 agar pages ka value na rahe to.
49
+
console.log(pages); //600
50
+
51
+
52
+
//nested array
53
+
54
+
let book = ["ADV. JS", 100, 200, ["Tech Gun", 2021]]; //nested array
55
+
let [name, pages, price, [Publication, Year]] = book;
56
+
57
+
console.log(Publication); //Tech Gun
58
+
console.log(Year); //2021
59
+
*/
60
+
61
+
62
+
//iska actual use kh p h
63
+
64
+
65
+
functionbook(){
66
+
//do something
67
+
return["Adv js",200];
68
+
}
69
+
70
+
//let name = book(); //isko hum normal var m na store karke array destructor karte hain.
0 commit comments