When using http, I receive an array of large objects with many values, some of which are irrelevant to me.
The object (represented as ...
) looks like this:
id: '45678',
attributes: {
title: 'This is a title!'
...
},
resources: [
{url: 'www.facebook.com', type: 'social media', ...},
{url: 'www.instagram.com', type: 'social media', ...},
],
...
If I have a component that needs to display specific values from the object and ignore the rest (...
), what would be the best approach?
Should I create a new array, map the original one, and only push a modified object with the necessary data? Also, when it comes to typing and creating interfaces in Angular, do I need to define all objects?
EDIT:
return this.http.get(this.url)
.pipe(
map((a: any) => {
const products = [];
a.items.map(obj => {
products.push({id: obj.id, resources: obj.resources, attributes: obj.attributes});
})
return products;
})
);