Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

204
Visualizações
Javascript compare two tables

I need help with comparing two tables that presents like this:

table A = [1, 2, 3, 4, 5, 6, 7],
table B = [2, 4]

I need to check if the table A contains numbers from table B and to put it in another array:

Expected output:

table C = [false, true, false, true, false, false, false]

Tried a few things but nothing works out for me. The table.includes method gives me following output

let isAdded = [];
  allObjectivesArray.forEach((element, index) => {
    if (allObjectivesArray.includes(reducedArr[0][element - 1])) 
isAdded.push(true);
    else isAdded.push(false);

});

// That is the output of above isAdded = [true, true, false, false, false, false, false]

Thank you for your help.

almost 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

You can map the array a and check in the callback if each item exists in the array b with includes function, if exists includes will return true if not will return false

const a = [1, 2, 3, 4, 5, 6, 7];
const b = [2, 4];

const result = a.map(i => b.includes(i))

console.log(result)

almost 4 years ago · Santiago Trujillo Relatório

0

const tableA = [1, 2, 3, 4, 5, 6, 7];
const tableB = [2, 4]

const fun =(ar, refAr)=>{
const booleanSet = ar.map((e, i) => refAr.includes(e))
console.log(booleanSet)
}
fun(tableA ,tableB)

almost 4 years ago · Santiago Trujillo Relatório

0

Try:

tableA = [1, 2, 3, 4, 5, 6, 7];
tableB = [2, 4];

let tableC = tableA.map((el) => 
  tableB.indexOf(el) != -1
);

console.log(tableC);

almost 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda