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

112
Vistas
Manipulating objects in array to take the value of a property from objects in another array?

I have a sorted array of books with a property called 'place'.

book:

{
  id : number,
  place: string
}

but then I also have an array of places with the property 'name'

place

id: number,
name: string

What I'd like to do is to manipulate the array of books so that in the exact order, the place property in a book takes the name value of the place object

result should be:

booksArr[0] == placeArr[0].name
booksArr[1] == placeArr[1].name
booksArr[2] == placeArr[2].name

and if the length of the placeArr > booksArr, then it should just ignore the rest, not do anything with it.

Is there any nifty way of doing that?

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

book.forEach((_, ind) => {
    book[ind]["place"] = place[ind]["name"]
});
about 4 years ago · Juan Pablo Isaza Denunciar

0

How about:

const books = [...] // Your array of books
const places = [...] // Your array of places
books = books.map((book) => ({ id: book.id, place: places.find((place) => place.id === book.place)) });
about 4 years ago · Juan Pablo Isaza Denunciar

0

You could iterate and use a short circuit for unequal arrays.

placeArray.some(({ name }, i) => {
    booksArray[i].place = name;
    return i + 1 >= booksArray.length;
});
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