Issue
getCardList() {
this.http
.get<CardList>
(BACKEND_IP + CARD_LIST)
.subscribe(data => {
console.log(data);
this.cardList = data;
console.log(this.cardList);
return this.cardList;
});
return this.cardList;
}
I get the answer from the backend:
0:
mass: (2) [25, 50]
name: "Tanks"
__proto__: Object
1:
mass: (2) [10, 15]
name: "Car"
__proto__: Object
----------
How do i get an array format
mass: (25)
name: "Tanks"
mass: (50)
name: "Tanks"
mass: (10)
name: "Car"
mass: (15)
name: "Car"
by this.cardList.map
Solution
You can map
your desired objects and then flat data through flatMap
method:
const arr = [
{ mass: [25, 50], name: "Tanks" },
{ mass: [10, 15], name: "Car" }
];
const result = arr.flatMap(a => a.mass.map(s=> ({mass: s, name: a.name})));
console.log(result);
Answered By - StepUp
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.