Skip to content

Commit e4ac95b

Browse files
committed
spread operator
1 parent eeb1c7d commit e4ac95b

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

spread_operator.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,21 @@ <h2>Spread operator</h2>
133133

134134
console.table(studentInfoArr);
135135

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+
136151
</script>
137152
</body>
138153
</html>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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>

0 commit comments

Comments
 (0)