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

227
Views
¿Cómo puedo encontrar el valor de otro valor en la misma línea con JavaScript (JSON)?

Estoy tratando de obtener las "Respuestas correctas" de un número.

Aquí hay una muestra del JSON:

 { "questions": [ { "number": 3, "question": "☀️ ➕ 🌼 = ?", "answers": [ "🌻sunflower", "BIRTHDAY", "iPhone", "MOON CAKE" ], "correctAnswers": [ "🌻sunflower" ], "random": true, "timeLimit": "24" }, { "number": 1, "question": "⭐️ ➕ 🐟 =❓ ", "answers": [ "STAR FISH", "iPhone", "MOON CAKE", "HOT DOG" ], "correctAnswers": [ "STAR FISH" ], "random": true, "timeLimit": "20" }, { "number": 7, "question": "👁 ➕ ☎ = ", "answers": [ "SUNGLASSES", "SUNFLOWER", "HOUSEPAINT", "IPHONE" ], "correctAnswers": [ "IPHONE" ], "random": true, "timeLimit": 15 }, ] }

Estoy tratando de encontrar el "número": 1, O un número aleatorio dentro de las "preguntas" y luego encontrar las "Respuestas correctas" de ese número.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

const array = { "questions": [ { "number": 3, "question": "☀️ ➕ 🌼 = ?", "answers": [ "🌻sunflower", "BIRTHDAY", "iPhone", "MOON CAKE" ], "correctAnswers": [ "🌻sunflower" ], "random": true, "timeLimit": "24" }, { "number": 1, "question": "⭐️ ➕ 🐟 =❓ ", "answers": [ "STAR FISH", "iPhone", "MOON CAKE", "HOT DOG" ], "correctAnswers": [ "STAR FISH" ], "random": true, "timeLimit": "20" }, { "number": 7, "question": "👁 ➕ ☎ = ", "answers": [ "SUNGLASSES", "SUNFLOWER", "HOUSEPAINT", "IPHONE" ], "correctAnswers": [ "IPHONE" ], "random": true, "timeLimit": 15 }, ] }; const { questions } = array; // Find by number const correctAnswersByNumber = qNumber => { const q = questions.find(({ number }) => number === qNumber); if (!q) { return false; } return q.correctAnswers; }; console.log(correctAnswersByNumber(3)); // Question by number === 3 // Random question const randomCorrectAnswers = questions[Math.floor(Math.random() * questions.length)].correctAnswers; console.log(randomCorrectAnswers);
about 4 years ago · Juan Pablo Isaza Report

0

Elija una pregunta aleatoria usando random. Luego muestra las propiedades correctas.

 var data = { "questions": [ { "number": 3, "question": "☀️ ➕ 🌼 = ?", "answers": [ "🌻sunflower", "BIRTHDAY", "iPhone", "MOON CAKE" ], "correctAnswers": [ "🌻sunflower" ], "random": true, "timeLimit": "24" }, { "number": 1, "question": "⭐️ ➕ 🐟 =❓ ", "answers": [ "STAR FISH", "iPhone", "MOON CAKE", "HOT DOG" ], "correctAnswers": [ "STAR FISH" ], "random": true, "timeLimit": "20" }, { "number": 7, "question": "👁 ➕ ☎ = ", "answers": [ "SUNGLASSES", "SUNFLOWER", "HOUSEPAINT", "IPHONE" ], "correctAnswers": [ "IPHONE" ], "random": true, "timeLimit": 15 }, ] }; // Let's choose a random question let question = data['questions'][Math.floor(Math.random() * data['questions'].length)]; console.log(question.question, question.correctAnswers)

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!