I have an array of booking and types. From these two arrays I need to build an object. Everything works great, except for the types. Types return an array in each object (same). How can you return the correct object?
JavaScript
x
14
14
1
const booking = [{row: 1, num: 2, level:3}]
2
const types = [1,2,3,4,5]
3
4
export const selectResult = createSelector([selectBooking, selectTypes], (booking, types) => {
5
return booking.map((book) => {
6
return {
7
row: book.row,
8
num: book.num,
9
levelId: book.level,
10
discount: types
11
}
12
})
13
})
14
Advertisement
Answer
found a solution to my problem. It was enough to add indexes
JavaScript
1
14
14
1
export const selectResult = createSelector(
2
[selectBooking, selectTypes, selectPrices],
3
(booking, types) => {
4
return booking.map((book, idx) => {
5
return {
6
row: book.row,
7
num: book.num,
8
levelId: book.level,
9
type: types[idx]
10
}
11
})
12
}
13
)
14