-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdestruture.js
More file actions
39 lines (31 loc) · 978 Bytes
/
Copy pathdestruture.js
File metadata and controls
39 lines (31 loc) · 978 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
27
28
29
30
31
32
33
34
35
36
37
38
// The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values
// from arrays, or properties from objects, into distinct variables.
let arr = ["hi","my" ,"name","is"]
// let a arr[l]
// let b[2]
// console.log(a)
// console. log(b)
//another way of doin this is
let [a,b,c,d] = arr
console.log(a)
console.log(b)
//this is called destructuring of arrays
//destructuring objects
var person1={
firstname:"Charles",
lastname:"Saurav",
age : 20,
interest : ["networks","web designing","hacking","machine learning"],
address :{
State : "Jharkhand",
City : "Ranchi",
pincode : 834003
}
}
//To get the values we must always use the keys value only ,you can also use the alias name for it but you need keys
//objects descturing is done using curly braces
let{firstname:f,lastname:l,age:y,interest:[x],address:{State:s}}=person1
console.log(f)
console.log(l)
console.log(x)
console.log(s)