I made a function in my JavaScript, here is the scene: Please note, the code below is just for my scenario, its not working.
getData('bill', 'userAge');
Function getData(u, variable) {
fetch(`url`).then(r=> { return response.json();})
.then(u => {
var userFullName = u.fullname;
var userAge = u.age;
var userGender = u.gender
return variable
});
}
when I execute the function getData('bill', 'userAge')
which userAge
is the variable name inside the function. And the function will return the value from variable name: userAge
inside the function, so I dont have to write another code like, if(variable=='userAge') return userAge
;
Is it possible ? Just asking, because I have ton of variables in my function, for now I'm still using if(variable=='userAge') return userAge