(function () {
"use strict";
const person = {
name: "John Doe",
age: 30,
hobbies: ["reading", "traveling", "coding"],
};
const { hobbies, name, age } = person; // descructure
hobbies.forEach((item, idx) => passInfo(item, idx, { name, age })); // pass function into the foreach
function passInfo(item, idx, ...args) {
console.log({ item, idx, args });
}
})();
// another example
const test = [3, 5, 6, 7, 8, 0, "", null, undefined, "testing"];
test.forEach(listItem);
function listItem(item, number, total) {
return `<li class="${number}">${item} ${number} of ${total}</li>`;
}