Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
how to build object JS

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?

const booking = [{row: 1, num: 2, level:3}]
const types = [1,2,3,4,5]

export const selectResult = createSelector([selectBooking, selectTypes], (booking, types) => {
    return booking.map((book) => {
        return {
            row: book.row,
            num: book.num,
            levelId: book.level,
            discount: types
        }
    })
})
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

If you want to have an object of each booking with one type in it, you can use it like this

booking.map(book => {
    return types.map(type => ({
            row: book.row,
            num: book.num,
            levelId: book.level,
            discount: type
        }))
})

If you want to have discount values as an object instead of having an array, you can get it like this

booking.map((book) => {
        return {
            row: book.row,
            num: book.num,
            levelId: book.level,
            discount: {...types}
        }
    })
about 4 years ago · Juan Pablo Isaza Report

0

found a solution to my problem. It was enough to add indexes

export const selectResult = createSelector(
    [selectBooking, selectTypes, selectPrices],
    (booking, types) => {
        return booking.map((book, idx) => {
            return {
                row: book.row,
                num: book.num,
                levelId: book.level,
                type: types[idx]
            }
        })
    }
)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!