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

322
Visualizações
How to find item in array in React

I want to retrieve data from a json file and then match it with the value of an existing variable and if the variable value matches the data in json it will display a message "a" and if it does not match it will display a message "b".

the json file is like this

["23435","87567", "34536","45234","34532","65365"]
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Since this is not a proper JSON format file, you can load it in simply as a string:

import arrayFile from './arrayFile.txt';

Then, if your file is truly just an array hidden with nothing else, you can do something like this to get it into an array format:

const newArray = JSON.parse(arrayFile);
over 4 years ago · Santiago Trujillo Relatório

0

What you want is to find a value in an array.

You can use includes

    const array = ["23435","87567", "34536","45234","34532","65365"]

    const aConstant = "23435"

    return (<div>{ array.includes(aConstant) ? 'a' : 'b' }</div>)

Same thing with indexOf

    const array = ["23435","87567", "34536","45234","34532","65365"]

    const aConstant = "23435"

    return (<div>{ array.indexOf(aConstant) !== -1 ? 'a' : 'b' }</div>)

You can also try filter

    const array = ["23435","87567", "34536","45234","34532","65365"]

    const aConstant = "23435"

    return (<div>{ Boolean(array.filter( x => x === aConstant)) ? 'a' : 'b' }</div>)

And even find

    const array = ["23435","87567", "34536","45234","34532","65365"]

    const aConstant = "23435"

    return (<div>{ array.find( x => x === aConstant) ? 'a' : 'b' }</div>)
over 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