Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

150
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda