I have an Angular Service which sends a data service call and returns an array of objects containing multiple layers of data. I want to be able to filter thrhough that data and return only the object that contains a specific value.
this.service.getRecords().pipe(
map(item => item.filter(items => items.attributes['identifier'].value === '101723102')),
tap(item => console.log(item)),
).subscribe();
The attributes[] has thosands of objects like the one stated below:
[20000]: {identifier:"1239213", something: "42142", something: "42142", something: "42142".....}
I am trying to filter and return the objects if the identifier is equal to something but am not sure how to access the value since it is nested and I cannot use dot notation.
Current code returns error: Cannot read property 'identifier' of undefined
[EDIT]: This is the service I am using
export class DataViewerService {
_recordDetails: Observable<DataClass[]>;
// resource service contains code to retrieve data constructor(private _resourceService: ResourceService, ) { }
getRecords() {
return this._recordDetails = this._resourceService.search(CONSTANT, {})
.pipe(map(extractRecords))
.pipe(shareReplay()) as Observable<Data[]>;
}
function extractRecords(result) {
const records = [];
if (!isNullOrUndefined(result)) {
result.forEach(r => {
if (!isNullOrUndefined(r['payload'])) {
records.push(r.payload);
}
});
}
return records;
}
[EDIT]: Items Object is as follows:
{
attributes: [],
descrtiption: "",
name: "",
label: ""
}
I need to access the objects within the attributes[] of filter which looks like
attributes: [
{
identifier: "1243212",
something: "",
...
}
This is the interface and the object returns is of type Data
export interface Data {
name: string;
label: string;
attributes: DataAttributes[];
}
interface DataAttributes {
attributes: [
identifier: string;
something: string;
];
something: string;
...
}
And the service returns the attributes[] which contains the values I want to filter