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

176
Vistas
How to change map array to comparable numbers?

Project contains 7 cards , each card has own ID. I selected this ID . I have data in JS file , this data has 7 objects with ID , I want compare card ID with data ID , IF THIS IDs WILL MATCH , THEN WILL PRINT IT . console.log show me this

3 = card ID

(7) [1, 2, 3, 4, 5, 6, 7] = data file shows me array

How to change this array , I could compare card ID ?

const cardbody = document.querySelectorAll('.card')

cardbody.forEach(function(btn) {
  console.log(btn)  // it shows me current card
  
  btn.addEventListener('click', function(e) {
    
    const bt = e.currentTarget.dataset.id
    console.log(bt)  // 3 


  // data from JS file  this return arrays
   const dataid = cabins.map(function(item) {  
     return item.id
   })
   console.log(dataid)  //(7) [1, 2, 3, 4, 5, 6, 7]

   if(dataid === bt ) {
     console.log('red')
     }

  })
})


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

0

If you just need to know if the bt is in any of the id properties, use the some() method. You don't need to create an array first.

cardbody.forEach(function(btn) {
  console.log(btn) // it shows me current card

  btn.addEventListener('click', function(e) {

    const bt = e.currentTarget.dataset.id
    console.log(bt) // 3 

    if (cabins.some(item => item.id == bt)) {
      console.log('red')
    }
  })
})
about 4 years ago · Juan Pablo Isaza Denunciar

0

const arr = [1, 2, 3, 4, 5, 6, 7];
const id = 3;

// existance
if (arr.includes(id)) {
  console.log(`${id} exists`);
}

// findIndex
if (arr.indexOf(id) >= 0) {
  console.log(`${id} found at arr[${arr.indexOf(id)}]`);
}

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