I have 2 arrays of objects. One array is the original array, and the other array contains the modified array. The modified array can include new objects, edited objects, or deleted objects in the settingValueDtoList
.
Currently, I am working on writing code for a new record in the settingValueDtoList. If I add a new object to any settingValueDtoList, its id will be like a0, a1, or a2. I iterate through both arrays and check if the id is not present in the original
array, indicating a new object. I then push that object into my addSettingArray
variable.
How can I retrieve the new record whose id is not in the original array?
This is my approach:
compareSetting(settingArray: Array<any>) {
console.log('abc', this.settingObject)
console.log('settingArray',settingArray)
let settingIndex = 0;
this.settingObject.forEach(unmodifiedSetting => {
let modifiedSetting = settingArray[settingIndex];
modifiedSetting.settingValueDtoList.forEach(editedSettingValue => {
unmodifiedSetting.settingValueDtoList.forEach(uneditedSettingValue => {
if(editedSettingValue.id != uneditedSettingValue.id) {
this.addSettingArray.push(editedSettingValue);
}
});
})
settingIndex++;
})
console.log('add', this.addSettingArray)
}