I am trying to add one new key-value
pair to json object using JavaScript for loop but its not working as expected. I am explaining my code below.
for (var i=0; i < CustomerGroup.length; i++) {
const customerCollection = loadMongoModel(CUSTOMERS_COLLECTION);
const data = await customerCollection.find({_id: CustomerGroup[i]['CustomerId']});
//console.log('data', data);
CustomerGroup[i].CustomerName = data[0]['CustomerFullName'];
console.log('data', data[0]['CustomerFullName']);
}
let result = {'record': CustomerGroup, 'count': CustomerGroupCount};
console.log('cust', result);
Here I need to add CustomerName
key to CustomerGroup
json object but it can not add this key and its value. I need after fetching some data the new value will be assigned to this json object with new key name.