File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change @@ -133,6 +133,21 @@ <h2>Spread operator</h2>
133
133
134
134
console . table ( studentInfoArr ) ;
135
135
136
+ /*
137
+ Example no 4 -----------------------------
138
+ Calling Function without Apply
139
+ */
140
+ let txt = [ 'Hi!' , 'How are you ?' ] ;
141
+ function showWithApply ( txt1 , txt2 ) {
142
+ console . log ( txt1 + ' ' + txt2 ) ;
143
+ }
144
+ showWithApply . apply ( null , txt ) ;
145
+
146
+ function showWithoutApply ( txt1 , txt2 ) {
147
+ console . log ( txt1 + ' ' + txt2 ) ;
148
+ }
149
+ showWithoutApply ( ...txt ) ;
150
+
136
151
</ script >
137
152
</ body >
138
153
</ html >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html >
3
+ < head >
4
+ < title > Spread operator in function arguments</ title >
5
+ </ head >
6
+ < body >
7
+ < h2 > Spread operator in function arguments</ h2 >
8
+ < script >
9
+ let studentArr = [
10
+ {
11
+ stud_id : 1 ,
12
+ stud_name : 'Student 1' ,
13
+ stud_marks : 60
14
+ } ,
15
+ {
16
+ stud_id : 2 ,
17
+ stud_name : 'Student 2' ,
18
+ stud_marks : 55
19
+ } ,
20
+ {
21
+ stud_id : 3 ,
22
+ stud_name : 'Student 3' ,
23
+ stud_marks : 76
24
+ } ,
25
+ {
26
+ stud_id : 4 ,
27
+ stud_name : 'Student 4' ,
28
+ stud_marks : 87
29
+ } ,
30
+ {
31
+ stud_id : 5 ,
32
+ stud_name : 'Student 5' ,
33
+ stud_marks : 90
34
+ }
35
+ ] ;
36
+ let showmark = ( { stud_name, stud_marks} ) => {
37
+ console . log ( stud_name + ' has got total ' + stud_marks + ' marks' ) ;
38
+ }
39
+ studentArr . forEach ( ele => showmark ( { ...ele } ) ) ;
40
+ </ script >
41
+ </ body >
42
+ </ html >
You can’t perform that action at this time.
0 commit comments