Is there any way to pass object properties dynamically as individual parameters?

I have an object like below

const myObject = {
  param1: 'val-1',
  param1: myFunction,
  param3: {test: 'test'},
};

Now is there any dynamic way so I can pass this object properties as individual parameters like below?

callBack('val-1', myFunction, {test: 'test'});

Note: Number of Object properties are dynamic.

26 thoughts on “Is there any way to pass object properties dynamically as individual parameters?”

  1. If, as it is in the question, the object’s properties happen to be in the order you want to pass into the callback, you can use Object.values and spread them:

    callBack(...Object.values(myObject));
    
    Reply

Leave a Comment