In one of my angular application I have interface
<code>export interface box {
row : number;
col : number;
value : string;
selected : boolean;
};
</code>
<code>export interface box {
row : number;
col : number;
value : string;
selected : boolean;
};
</code>
export interface box {
row : number;
col : number;
value : string;
selected : boolean;
};
And in component.ts ,
<code>obj : box[][] = []
allobj : any = []
</code>
<code>obj : box[][] = []
allobj : any = []
</code>
obj : box[][] = []
allobj : any = []
In further I do get obj as,
<code>this.obj =
[
[{"row":0,"col":0,"value":"00"},{"row":0,"col":1,"value":"01"},{"row":0,"col":2,"value":"02"}],
[{"row":1,"col":0,"value":"10"},{"row":1,"col":1,"value":"11"},{"row":1,"col":2,"value":"12"}],
[{"row":2,"col":0,"value":"20"},{"row":2,"col":1,"value":"21"},{"row":2,"col":2,"value":"22"}]
]
</code>
<code>this.obj =
[
[{"row":0,"col":0,"value":"00"},{"row":0,"col":1,"value":"01"},{"row":0,"col":2,"value":"02"}],
[{"row":1,"col":0,"value":"10"},{"row":1,"col":1,"value":"11"},{"row":1,"col":2,"value":"12"}],
[{"row":2,"col":0,"value":"20"},{"row":2,"col":1,"value":"21"},{"row":2,"col":2,"value":"22"}]
]
</code>
this.obj =
[
[{"row":0,"col":0,"value":"00"},{"row":0,"col":1,"value":"01"},{"row":0,"col":2,"value":"02"}],
[{"row":1,"col":0,"value":"10"},{"row":1,"col":1,"value":"11"},{"row":1,"col":2,"value":"12"}],
[{"row":2,"col":0,"value":"20"},{"row":2,"col":1,"value":"21"},{"row":2,"col":2,"value":"22"}]
]
and will be pushing this object to another array.
<code>this.allobj.push(this.obj)
</code>
<code>this.allobj.push(this.obj)
</code>
this.allobj.push(this.obj)
In next iteration, get obj as
<code>this.obj =
[
[{"row":0,"col":0,"value":"99"},{"row":0,"col":1,"value":"01"},{"row":0,"col":2,"value":"02"}],
[{"row":1,"col":0,"value":"10"},{"row":1,"col":1,"value":"11"},{"row":1,"col":2,"value":"12"}],
[{"row":2,"col":0,"value":"20"},{"row":2,"col":1,"value":"21"},{"row":2,"col":2,"value":"22"}]
]
</code>
<code>this.obj =
[
[{"row":0,"col":0,"value":"99"},{"row":0,"col":1,"value":"01"},{"row":0,"col":2,"value":"02"}],
[{"row":1,"col":0,"value":"10"},{"row":1,"col":1,"value":"11"},{"row":1,"col":2,"value":"12"}],
[{"row":2,"col":0,"value":"20"},{"row":2,"col":1,"value":"21"},{"row":2,"col":2,"value":"22"}]
]
</code>
this.obj =
[
[{"row":0,"col":0,"value":"99"},{"row":0,"col":1,"value":"01"},{"row":0,"col":2,"value":"02"}],
[{"row":1,"col":0,"value":"10"},{"row":1,"col":1,"value":"11"},{"row":1,"col":2,"value":"12"}],
[{"row":2,"col":0,"value":"20"},{"row":2,"col":1,"value":"21"},{"row":2,"col":2,"value":"22"}]
]
And this will be pushed to allobj as one of first value is different (00 & 99). In short , i want to insert obj array into allobj array if not exists. means any of the “value” in this.obj is not already present in allobj. I tried below solution but that is also not working.
<code>let temp=JSON.parse(JSON.stringify(this.obj))
let arr_str = this.allobj.map(JSON.stringify)
!arr_str.includes(JSON.stringify(temp)) && this.allobj.push(temp)
this.allobj.push(temp)
</code>
<code>let temp=JSON.parse(JSON.stringify(this.obj))
let arr_str = this.allobj.map(JSON.stringify)
!arr_str.includes(JSON.stringify(temp)) && this.allobj.push(temp)
this.allobj.push(temp)
</code>
let temp=JSON.parse(JSON.stringify(this.obj))
let arr_str = this.allobj.map(JSON.stringify)
!arr_str.includes(JSON.stringify(temp)) && this.allobj.push(temp)
this.allobj.push(temp)
need some suggestion.