I have the following JSON File: http://pastebin.com/1TguvZXc
The duplicate 'body' can be found in the array by traversing through the array:
models[x].years[y].styles[z].submodel.body
In other words:
models[0].years[0].styles[0].submodel.body
should be checked for duplicates in:
models[0].years[0].styles[1].submodel.body
models[0].years[0].styles[2].submodel.body
models[0].years[0].styles[n].submodel.body
The rest of the data is useless for me.
I have the following pipe:
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'filterByCategory'
})
export class FilterByCategoryPipe implements PipeTransform {
transform(input: any , search: string): any[] {
if (input === undefined || input.length === 0) {
return input;
}
const filteredArr: Array<any> = JSON.parse(JSON.stringify(input));
for (const model of filteredArr) {
for (const year of model.years) {
year.styles = year.styles.filter(style => {
return style.submodel.body === search;
});
}
}
return filteredArr;
}
}
How would I add an additional 'test' to my .filter function that checks if the value of 'submodel.body' exists in any of the styles array?