1const avengers = ['thor', 'captain america', 'hulk'];
2avengers.forEach((item, index)=>{
3 console.log(index, item)
4})
1let numbers = ['one', 'two', 'three', 'four'];
2
3numbers.forEach((num) => {
4 console.log(num);
5}); // one //two //three // four
1var arr = [1, 2, 3, 4, 5, 6];
2
3//var sum = 0;
4arr.forEach(function (value, index, array){ // Built in method
5 //sum += value;
6 console.log(value, index, array);
7})
8
9//console.log(sum); // We can print sum of all Array element (if those are numbers)
10
11// function forEach(arr, cb){ // How forEach() method works
12// for (var i = 0; i<arr.length; i++){
13// cb(arr[i], i, arr);
14// }
15// }
16// var sum = 0;
17// forEach(arr, function (value, index, arr){
18// console.log(value, index, arr);
19// sum += value;
20// })
21// console.log(sum);
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