How to work with the obj from a method callback?

I want the array.forEach to

for each of its elements, console log the entire array once, logging array.length times in total

instead of just console log each of its 10 elements.

To accomplish this, I need to have a reference to the array inside the array.forEach(callback) function:

 array.forEach(
(element)  => {
console.log(the entire array, not the element)
} );

Or this example:

const callbackMale = () => {
  let name = this.name;
  return 'Mr. ' + name;
}

const callbackFemale = () => {
  let name = this.name;
  return 'Ms. ' + name;
}
//I need to use the 'name' property value of the object which a method using this callback is called upon
// i need this.name === object.name for the callback to work
};

const obj 1= {
  name: 'Foo'; 
  methodA(callback){
console.log(callback());
}
}

const obj2= {
  name: 'Bar'; 
  methodB(callback){
console.log(callback());
}
}

obj1.methodA(callBackMale); // Mr. Foo
obj2.methodB(callBackFemale); //Ms. Bar



(OR in general, let the callback do something to/with the obj/arr the method is called upon)

I believe the 3rd parameter of the callback function is the array its being that is being looped through for the .forEach mthod for arrays. Mozilla reference for .forEach

So if you want to log the entire array for each element, you might do

array.forEach( (element, index, arr) => console.log(arr) );

or just

array.forEach( () => console.log(array) );

[codebyte language=javascript]
const array = [“mouse”, “cat”, “dog”];
array.forEach( (el, i, arr) =>
console.log(el + " is found at index " + i + " in array [" + arr + “]”)
);

For the callback functions, involving name,
you could change the name to be a parameter of the function:

const callbackMale = (name) => {
  return 'Mr. ' + name;
}

or just

const callbackMale = (name) => 'Mr. ' + name;

and then adjust the methods in each object so that callback has an argument containing the name.

const obj1 = {
  name: 'Foo', 
  methodA(callback){
    console.log(callback(this.name));
  }
}

obj1.methodA(callbackMale); // Mr. Foo

Alternatively, you could keep the much of callbackMale function the way you have it already (but change it to a function declaration), and set what is used for this when the function is called by using the .call for the function and thus having callbackMale.call(this)

function callbackMale() {
  let name = this.name;
  return 'Mr. ' + name;
}

const obj1 = {
  name: 'Foo', 
  methodA(callback){
    console.log(callback.call(this));
  }
}

obj1.methodA(callbackMale); // Mr. Foo

Note that the function keyword is needed [to make it a function declaration] so that the this works properly in the callbackMale function.