1const avengers = ['thor', 'captain america', 'hulk'];
2avengers.forEach((item, index)=>{
3 console.log(index, item)
4})
1///Simple One
2var a = ["a", "b", "c"];
3a.forEach(function(entry) {
4 console.log(entry);
5});
6
7
8///Function concept
9
10var fruits = ["apple", "orange", "cherry"];
11fruits.forEach(myFunction);
12
13function myFunction(item, index) {
14 document.getElementById("demo").innerHTML += index + ":" + item + "<br>";
15}
16
1let colors = ['red', 'blue', 'green'];
2// idx and sourceArr optional; sourceArr == colors
3colors.forEach(function(color, idx, sourceArr) {
4 console.log(color, idx, sourceArr)
5});
6// Output:
7// red 0 ['red', 'blue', 'green']
8// blue 1 ['red', 'blue', 'green']
9// green 2 ['red', 'blue', 'green']
1// result.params.detail = {
2// "status": true,
3// "message": "",
4// "params": {
5// "pay_credit_remain": 115,
6// "month_expiry": "15",
7// "detail": [
8// {
9// "credit": "70",
10// "create_date": "2020-10-16",
11// "expiry_date": "2022-01-16"
12// },
13// {
14// "credit": "45",
15// "create_date": "2020-10-17",
16// "expiry_date": "2022-01-17"
17// }
18// ]
19// }
20//}
21
22
23detail = "<ul>";
24result.params.detail.forEach((val) => {
25 detail = detail + sprintf(lang.pay_credit_detail, val.credit, val.expiry_date);
26});
27detail += "</ul>";
28
29$('#pay_credit_remain').html(detail);
30
1const marks = [12, 17, 14];
2let sum = 0;
3
4marks.forEach(mark => {
5 sum += mark;
6});