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

217
Vistas
How do I get numbers of element from a JSON file with Typescript
  [
     {
       "dataset_id": "courses",
       "dept": "phys",
       "id": "301",
       "avg": 71.67,
       "instructor": "bryman, douglas",
       "title": "elec & magnetism",
       "pass": 146,
       "fail": 6,
       "audit": 0,
       "uuid": 441,
       "year": "2015"
     },
     {
       "dataset_id": "courses",
       "dept": "phys",
       "id": "301",
       "avg": 71.67,
       "instructor": "",
       "title": "elec & magnetism",
       "pass": 146,
       "fail": 6,
       "audit": 0,
       "uuid": 442,
       "year": "2015"
     },
     {
       "dataset_id": "courses",
       "dept": "phys",
       "id": "301",
       "avg": 73.07,
       "instructor": "louis-martinez, domingo",
       "title": "elec & magnetism",
       "pass": 113,
       "fail": 4,
       "audit": 0,
       "uuid": 5957,
       "year": "2013"
     }
   ]

Here is my JSON file and I intend to get a number of elements which is suppose to be 3. I tried to use:

    let num = JSON.parse(file).result.length;

I got a result of Syntax error says "Unexpected token c in JSON at position 0". What did I do wrong?

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

0

You'll need to provide a bit more context on how you're getting "file". Is it from an ajax request, is it a static file in your project directory, etc.?

However, since you're using typescript im wagering it is a static file (client or server side shouldnt matter).

You'll probably need to just export it correctly. Add export const variableName = [...] and then you should be able to import it in any file via import file from './filepath'. You shouldnt need to JSON.parse() it.

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