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

177
Visualizações
Can't convert string to boolean

I'm trying to parse an ini file using ini. However, I can't manage to convert my string value to a boolean and I think I'm going crazy!

I have tried the obvious variable = (value == 'true'); approach listed below:

  • How can I convert a string to boolean in JavaScript?
  • Converting string "true" / "false" to boolean value [duplicate]
    let myBool;
    for (const [key, value] of iniObject) {
        console.log(`pair: ${key} - ${value}`);
        if(key == 'testBool') {
            myBool = (value == 'true');
            console.log(`myBool set to ${myBool} (${typeof myBool}) - value: ${value}`);
        }
    }

Instead of setting myBool to true, it is set to false! The console.log() output is the following, showing that the input value is indeed "true":

    [1] pair: testBool - true
    [1] myBool set to false (boolean) - value: true

I have also tried the following without success:

    myBool = (JSON.parse(value) == 'true');
or
    myBool = (value == 'true') ? true : false;

The corresponding line in the ini is testBool=true, so nothing special. What am I missing? I feel like an idiot for having spent the last 3 hours on this, so I would really appreciate some help on this.

Thank you for your time!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I don't know how the ini works, but did you check what is the type of value?

Maybe it has already parsed it as a boolean and that is why you get false when comparing?

"true" == true // false
about 4 years ago · Juan Pablo Isaza 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