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

133
Visualizações
How can I return a parameter of .Json file based on the User's input in Javascript program?

I have a problem with printing the value from .json file. Based on the user's input, program should access .json file and return parameter same as input. But when I run the code it returns undefined. I tried using toLowerCase, but that didn't work for me. Is it possible to extract the same value as a user input from .json file?

GitHub link for more context and .json file itself: https://github.com/TheRadioDept/technical-question

const data = require('/home/user/progs/JS/countries.json'); /* Passing a .json file into javascript*/

var keys = ['cym','deu','fra','hrv','ita','jpn','nld','por','rus','spa'];  /* creating an array of translation keys */
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});


rl.question('Please enter the translation key ', (key) => {
    if (keys1.includes(key)){
        console.log(data.map(point=>point.translations.key));
    }
else {
    console.log("Translation key is not supported in this program. ");
}
rl.close();
});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try using

data.map(point=>point.translations[key])

When you use .key, Javascript looks for a key prop inside data.translations but you want to look for dynamic value of key which could be parsed using above format.

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