I have a small form where I enter values (id's and names) and store them in array by clicking a button, but I want to validate if there's an existing id key value in this array because I don't want to add repeated id key values.
Currently I have this:
<div class="form">
<input type="text" id="idperson"><input type="text" id="name">
<button id="add" type="button">ADD</button>
</div>
<script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
<script>
var people = [];
$("#add").click(function(){
var iduser = $("#idperson").val();
var name = $("#name").val();
if(people["idperson"]!=iduser){
people.push({idperson:iduser,nameperson:name});
}
console.log(people);
});
</script>
But it's not working because it continues storing repeated idperson values when I enter info in the form:
I'm sorry if I'm forgetting something, I'm newbie on this.
How can I fix it? I'd like some help.
