Answer the question
In order to leave comments, you need to log in
How to replace data in an array object and return a new array object?
Good time!
there is such a data structure
{
books: [
{
id: '200',
author: '4124',
name: '412',
imgUrl: 'data:image/jpeg;base64'
}
]
}
Object.assign({}, state, {
books: [
...state.books,
action.book
]
{
books: [
{
id: '200',
author: 'new author',
name: 'new name',
imgUrl: 'some img'
}
]
}
const changedItem = action.book
Object.assign({}, state, {
books: state.books.map(item => item.id === changedItem.id ? changedItem : item)
});
Answer the question
In order to leave comments, you need to log in
How to replace data in an array object and return a new array object?
action.book.map = function (book) {
book.imgUrl = '/img/example.jpg'
return book
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question