How can I create a new JSON
array in jquery with comparing existing array? if the array value exists then change the value or if new then push the new value
$(document).on('change','#orderedMedicines',function(){
Medicines=$('#orderedMedicines').val(); /* Multiple Select Array */
medicineOrderList /* Existing Json Array */
/* [{medicineName: "medicine1 ", quantity: 5, stock: "50.00"},{medicineName: "medicine2 ", quantity: 10, stock: "50.00"}] */
var newMedicineOrderList=[]; /* New Json Array */
for(var i=0;i<Medicines.length;i++){
/* Push into new array but check with exist array if duplicates medicineName then want to get this stock and push instead of 0 in new array */
newMedicineOrderList.push({
medicineName: medicineWithUnits[Medicines[i]],
quantity: 0,
stock:medicineWithStock[Medicines[i]]
});
}
});