I'm trying to check if an array with multiple keys and values contains a duplicate if that's the case I don't want the duplicate to be pushed to the array.
Here's what I have so far (run inside a loop of items):
let positionArray = [], positionId="X", projectTitle="Title", xPosition=5, yPosition=10;
positionArray.push({
"Id": positionId,
"projectName": projectTitle,
"xPosition": xPosition,
"yPosition": yPosition
});
console.log($.inArray(positionId, positionArray));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Now all logic tells me that I should see something other than "-1" in the console when I run the loop, but it keeps returning "-1" every time. I have tried to figure out if it is simply because of .inArray()
only works for arrays without a key, but no luck.
What am I doing wrong here?