Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

201
Vistas
Turning JSON file content into Javascript object

What I want to do is read the JSON from a file and turn it into an array in Javascript.

My JSON looks like this

{
  "3-2": "10",
  "3-3": "20",
  "3-4": "30",
  "5-1": "4",
  "5-3": "8"
}

I know I should include the code I'm working with, but I've tried so many different ways and I cannot get anything to even remotely work, so I'm just looking for a simple solution (I'm using jQuery).

I just want to fetch the content of my JSON file, turn it into an array, and then be able to run a for loop to alert each item in the array.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

const json = '{"3-2":"10","3-3":"20","3-4":"30","5-1":"4","5-3":"8"}'
const obj = JSON.parse(json)
const arr = Object.entries(obj)

for (let i = 0; i < arr.length; i++) {
  const [key, val] = arr[i]
  console.log(`key: ${key}`)
  console.log(`val: ${val}`)
}

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can do it this way:

const yourJSON = {
  "3-2": "10",
  "3-3": "20",
  "3-4": "30",
  "5-1": "4",
  "5-3": "8"
}

for (key in yourJSON)
  console.log(key,":",yourJSON[key]) // here's your loop without converting into array

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda