I want to check if the input value is present in obj
, I display an alert ('num found'), then I push that num in the second obj2
, and this num becomes disabled from the obj1
, (I mean when I check again that num, it should be not available), I don't know if the best way is to add some extra key used
in object, or to create a new object obj2
then check first on it if the values have already been used.
var obj = [
{"id":1, "num":123, "val":20, "type":"weekend"},
{"id":2, "num":456, "val":30, "type":"weekend"},
{"id":3, "num":789, "val":15, "type":"semaine"},
{"id":4, "num":101, "val":25, "type":"semaine"}
];
var obj2 = [
];
html:
<input id="code"/> // val = 15
Js
jQuery("input").on("keydown",function search(e) {
if(e.keyCode == 13) { //when hit enter
var tik = jQuery(this).val();
console.log(tik);
var obj = [
{"id":1, "num":123, "val":20, "type":"week"},
{"id":2, "num":456, "val":30, "type":"week"},
{"id":3, "num":789, "val":15, "type":"day"},
{"id":4, "num":101, "val":25, "type":"day"}
];
if (tik in obj2.num) { // It doesn't work for me
alert("num found");
//I push this value to obj2
...
} else {
alert("num not found");
//I don't push to obj2
}