1
- let marks = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] ; // Array Declaration
1
+ const marks = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] ; // Array Declaration
2
2
3
3
// If we want 1 to 3 as different variables and 4 to 9 as full array then in such cases we use "rest" operator
4
4
5
- let [ first , second , third , ...remaining ] = marks ;
5
+ const [ first , second , third , ...remaining ] = marks ;
6
6
7
7
console . log ( first , second , third ) ; // Output 1 2 3
8
8
9
9
console . log ( remaining ) ; // Output [ 4, 5, 6, 7, 8, 9 ]
10
10
11
- let a = {
12
- name : "Swapnil" ,
13
- branch : "Comps" ,
14
- age : 19 ,
15
- college : "SIES"
11
+ const a = {
12
+ name : "Swapnil" ,
13
+ branch : "Comps" ,
14
+ age : 19 ,
15
+ college : "SIES"
16
16
} ;
17
17
18
- let { name , age, ...unwanted } = a ; // Here in unwanted all key and values expect the name and age will come this is different than arrays
18
+ const { name , age, ...unwanted } = a ; // Here in unwanted all key and values expect the name and age will come this is different than arrays
19
19
20
20
console . log ( unwanted ) ; // Output { branch: 'Comps', college: 'SIES' }
21
21
22
-
23
22
// "spread" operator can also be used for merging the arrays
24
23
25
- let array1 = [ 1 , 2 , 3 , 4 , 5 , 6 ] ;
24
+ const array1 = [ 1 , 2 , 3 , 4 , 5 , 6 ] ;
26
25
27
- let array2 = [ 6 , 7 , 8 , 9 , 10 ] ;
26
+ const array2 = [ 6 , 7 , 8 , 9 , 10 ] ;
28
27
29
- let combinedArray = [ ...array1 , ...array2 ] ; // Here "..." are considered as spread operation we are spreading the two arrays into one
28
+ const combinedArray = [ ...array1 , ...array2 ] ; // Here "..." are considered as spread operation we are spreading the two arrays into one
30
29
31
- console . log ( combinedArray ) ;
32
- /* Output
30
+ console . log ( combinedArray ) ;
31
+ /* Output
33
32
[
34
33
1, 2, 3,
35
34
4, 5, 6,
36
35
6, 7, 8,
37
36
9, 10
38
37
] */
39
38
40
- let obj1 = { // First Object
41
- name : "Swapnil" ,
42
- branch : "Comps"
39
+ const obj1 = { // First Object
40
+ name : "Swapnil" ,
41
+ branch : "Comps"
43
42
} ;
44
43
45
- let obj2 = { // Second Object
46
- age : 19 ,
47
- college : "SIES" ,
48
- }
44
+ const obj2 = { // Second Object
45
+ age : 19 ,
46
+ college : "SIES"
47
+ } ;
49
48
50
- let finalObj = { ...obj1 , ...obj2 } ; // Using Spread operator we are combining two objects into one
49
+ const finalObj = { ...obj1 , ...obj2 } ; // Using Spread operator we are combining two objects into one
51
50
52
51
console . log ( finalObj ) ; // Output { name: 'Swapnil', branch: 'Comps', age: 19, college: 'SIES' }
0 commit comments