I am using an object to pass in arguments, because the function has many parameters, and JavaScript doesnt support named arguments like Python.
I would like to check that all the args have a value passed in.
To do that I would like to loop over an array of the parameters, ['foo', 'bar', 'baz'] in the example below.
I would like to keep the code dry and not hardcode the list.
I can access an object of the arguments with arguments[0], but how does one access the parameters ['foo', 'bar', 'baz'] programatically without hardcoding it?
function run({foo, bar, baz}) {
const requiredKeys = ['foo', 'bar', 'baz']; // <- How to dynamically generate this
for (const key in requiredKeys) {
if (arguments[key] === null) throw `Please provide a value for ${key}`
}
console.log('done:', foo, bar, baz);
}
run({ foo: 1});