In the following object, I have a problem using the \'this\' reference:
function SampleObject(){
this.addObject = function(object){...}
...
// mo
const array1 = [
{name : "john", age: 20}, {name : "sarah", age: 70}
];
array1.forEach(element => this.print(element));
print = (data) =>
{
console.log(data.name);
}
// expected output: "john"
// expected output: "sarah"
There is better way to do this
array.forEach(obj => this.functionName(params));