$(document).on('change', '.units', function () {
var obj = $(this);
unit_id = parseInt($(this).val());
var item_array = [];
var unit_array = [];
var units = $(".units");
var items = $(".items");
$('#used_items tr').each(function () {
$(this).find('.items').each(function () {
item_array.push($(this).val());
});
$(this).find('.units').each(function () {
unit_array.push($(this).val());
});
});
var item_unit_associative_array = [];
for (var i = 0; i < units.length; i++) {
if (item_unit_associative_array[item_array[i]] == unit_array[i]) {
obj.val('');
return alert("Given Item Unit Already Selected");
}
else {
item_unit_associative_array[item_array[i]] = unit_array[i];
}
}
console.log(item_unit_associative_array););
From item_array and unit_array I want to build new object like
var item_unit_associative_array=[1:12, 1:13 ,1:14,2:10];
and finally want to check an object consists of key:value like
var test ={1:12}
is exists or not in the item_unit_associative_array
{1:12, 1:13 ,1:14,2:10}[{ 1: 12 },{ 1: 13 },{ 1: 14 },{ 2: 10 }], or an object which holds arrays:{ 1: [12, 13, 14], 2: [10] }