I want to implement a reusable helper function which can change the name of a variable to string value. For example, I have some parameters, the function will print which one is empty:
paramsHandler(name, address, mobileNum, ...){
if(!name){
console.log("name cannot be empty");
}
if(!address){
console.log("address cannot be empty");
}
if(!mobileNum){
console.log("mobileNum cannot be empty");
}
...
}
Now, I want to make it generalized, something like below, where key should be the string of the parameter name.
paramsHandler(...params){
for(const key of params){
if(!key){
console.log("key cannot be empty");
}
}
}
Do anyone knows how could I do this?