0

I have a callback function which can be re-usable based on the argument that is passed while calling the function, It will be helpful to decide the behavior of callback function

Callback function:

  sampleArray = [5, 3, 4, 6, 7];

  getProcessedData = (value, args) => {
    console.log('manoj', args);
    if(args === 'value a') {
      ...
    } else if (args === 'value b') {
      ...
    }
    return;
  };

I using array.every() function on the above array

sampleArray.every(getProcessedData, 'value A');
sampleArray.every(getProcessedData, 'value B');

But I'm not able to receive this 'value A' in getProcessedData() function, I have tried with few other way, but it didn`t work. Any suggestion would be helpful

Manoj G
  • 35
  • 5

1 Answers1

3

Use an anonymous function that passes the second argument.

sampleArray.every(el => getProcessedData(el, 'value A'));
Barmar
  • 741,623
  • 53
  • 500
  • 612