0

I would add a key value/value on my array objects "members".

I am on React JS with Akita.

addAge(): Observable<Member[]> {
return this.selectAll().pipe(
                map((allMembers) => ({...allMembers, age:10}))
            )
}

-

 dataQuery.addDatasWeek().subscribe(res => {
                this.setState({obj: res})
            })

I hope for membersWithAge :

[{id: 5, name: "Teddy, age: 10}, {id: 6, name: "Toto", age: 10},...]

but...

enter image description here

1 Answer 1

2

You're adding age to the allMembers object, you need to add it to each member inside allMembers.

addAge(): Observable < Member[] > {
  return this.selectAll().pipe(
    map((allMembers) => allMembers.map(member => ({
      ...member,
      age: 10
    })))
  )
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.