My current JavaScript setup looks like this:
var NAMES = [];
function INFO(id,first,middle,last){
var newMap = {};
newMap[id] = [first, middle, last];
return newMap ;
}
Next, I have the following code block:
for (var j = 0; j < NUMBER.length; j++) { //let's say there are three values
var my_name = all_names[j]; // which contains "185, 185, 185"
if (NAMES[my_name] !== 185){ //This is where I need to perform a check
NAMES.push(INFO(my_name,"sean","sdfsd","sdfsfd"));
}else{
}
}
alert(JSON.stringify(NAMES , null, 4));
Below is a screenshot of the alert displayed:
https://i.sstatic.net/91uqg.png
I used the number "185" for demonstration purposes. What I'm trying to achieve is checking if the id of 185
already exists, and if it does, proceed to the else
block. I've attempted using typeof
, undefined
, etc., but haven't been successful.
(In essence, I should only have one instance of "185").
Any suggestions or advice on how to accomplish this? Thank you!