Skip to content

Commit e9e09a2

Browse files
committed
add all 85 array destructor till line no 75
1 parent 1aa14be commit e9e09a2

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

85-array-destructing.html

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
<title>Array destructing</title>
9+
<link rel="stylesheet" type="text/css" href="">
10+
</head>
11+
12+
<body>
13+
<h1>array destructor</h1>
14+
<script src="js/85-array-destructing.js"></script>
15+
</body>
16+
17+
</html>

js/85-array-destructing.js

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
let book = ["ADV. JS", 200, 150];
3+
console.log(book[0]); //ADV. JS
4+
console.log(book[1]); //200
5+
6+
pahle hum array element ko aise access krte the.
7+
8+
9+
//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+
function book() {
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.
71+
//console.log(name); //(2) ['Adv js', 200]
72+
73+
let [booktitle, price] = book();
74+
console.log(booktitle); //Adv js
75+
console.log(price); //200

0 commit comments

Comments
 (0)