Level 28
- You're checking an object, not an array
- inArray checks values, you are trying to check keys with it :)
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am retrieving the session array from the controller using ajax, then in the loop checking the required value is present in the array index.
barcode = '010001'
data['session'] = {
"010001": {
"id": "010001",
"qty": 2
},
"010002": {
"id": "010002",
"qty": 1
}
}
// checking if the barcode is present in the array index
if(jQuery.inArray(barcode,data['session']) !== -1)
{
// barcode exist in the array
}
But I am always getting -1 as result
Please or to participate in this conversation.