You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
566 B
JavaScript
25 lines
566 B
JavaScript
|
5 years ago
|
var banks = ["DBS", "HSBC", "OCBC", "UOB"]; //Array
|
||
|
|
/*for (i=0; i<banks.length; i++) {
|
||
|
|
console.log(banks[i]);
|
||
|
|
}
|
||
|
|
*/
|
||
|
|
/*
|
||
|
|
let myFunction = function(item, index) { //iterate through the listof items
|
||
|
|
console.log(`${item} is at index ${index}` );
|
||
|
|
}
|
||
|
|
|
||
|
|
banks.forEach(myFunction); //forEach takes a CallBackFunction
|
||
|
|
*/
|
||
|
|
|
||
|
|
|
||
|
|
banks.forEach(function (item, index) { // LOOP
|
||
|
|
console.log(`${item} is at index ${index}`);
|
||
|
|
});
|
||
|
|
|
||
|
|
|
||
|
|
//using the last parameter
|
||
|
|
banks.forEach(function (item, index, arr) {
|
||
|
|
console.log("Using Array Index")
|
||
|
|
console.log(arr[index]);
|
||
|
|
});
|