Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!