If the variable oldData contains multiple objects, you can check if newData is included in it using:
if(!oldData.includes(newData))
For the original code provided in the description, a simple comparison between single objects can be done like this:
if(oldData! = newData)
If the code has been edited as per the description:
addNewType(rowdata) {
const newData = JSON.stringify(rowdata.value);
const oldData = JSON.stringify(this.items.value);
if(oldData.includes(newData)){
console.log('This element already exists in the detail list');
}
else this.addItem(this.createItem(null));
}
In case oldData has newData occurring at least twice:
addNewType(rowdata) {
const newData = JSON.stringify(rowdata.value);
const oldData = JSON.stringify(this.items.value);
if((oldData.split(newData).length - 1) >= 2){
console.log('This element already exists in the detail list at least TWICE');
}
else this.addItem(this.createItem(null));
}
Alternatively:
addNewType(rowdata) {
const newData = JSON.stringify(rowdata.value);
const oldData = JSON.stringify(this.items.value);
let newReg= new RegExp(newData, "g");
if((oldData.match(newReg) || []).length >= 2){
console.log('This element already exists in the detail list at least TWICE');
}
else this.addItem(this.createItem(null));
}