I am trying to check if any element exists in a JS object. To do this, I need to use any identifier passed to my method. I am currently struggling to use the value of a variable. That's what I'm doing:
data.entries.id
So, I have an object setup like:
var data = {
"entries" : {
}
};
Therefore, the part .idchecks for a specific identifier. If so, I do nothing; if it is not, I want to add it. At the moment, using data.entries.id, every time I just check if the "id" exists in the "records", which I don't want. Say my variable value was "part1", but instead data.entries.idI want it to be searched data.entries.part1.
So, how do I pass the value of a variable when I check this, as opposed to the name of the variable.
I hope this makes sense, and I hope you can help!
source
share