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

190
Vistas
How to set a value to true if an object exists in a list

I have a three lists, the first one is like this

[
  true,
  ['keyToOffice', false],
  false
]

The second one is like this:

[
  {
    reference: 'keyToOffice',
    a load of other irrelevant stuff
  },
  {
    reference: 'keyToHouse',
    a load of other irrelevant stuff
  }
]

The third one, my inventory is like this:

[
  'keyToOffice'
]

I would like to know if there is a way to update the second value of all the lists in the first list to true if the first item is inside of the third list. What would happen is that in ['keyToOffice', false], the false would become true because it is in the inventory list. If 'keyToOffice' was not in the inventory, then the false would stay false

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

0

If I understand your problem correctly, you don't need the second list. You can just iterate through the first list, and if the element is an array, and the string in it is included in the third list, change the boolean to true.

What map does is iterates through an array, and returns a one to one representation of that array (same number of elements), with certain elements changed according to the rules inside the function.

const firstList = [
  true,
  ['keyToOffice', false],
  false,
  true,
  ['keyToHouse', false],
  false,
  true,
  ['keyToCar', false],
  false,
]

const thirdList = [
  'keyToOffice',
  'keyToCar'
]

const firstListAmended = firstList.map(el => {
  if(Array.isArray(el)) {
    if(thirdList.includes(el[0])) {
        el[1] = true
    }
  }
  return el
})

console.log(firstListAmended)

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