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

242
Vistas
Unable to convert jquery ajax response to array javascript

I have an API which returns an array of format:

[
  {
    "abc": "def",
    "efg": "hij"
  },
  {
    "abc": "def",
    "efg": "hij"
  }
]

When I hit the service with jquery.ajax I am able to get a response

$.ajax({
url: URL,
type: 'GET',
dataType: 'JSON',
xhrFields: {
withCredentials: false
},
success: function (data) {
console.log(data);
},
error: function (request, error) {});

On java script when I try to check the data type of data it is of type Object. When I directly print data on console

0: Object { "abc": "def", "egf":"ghi " }​​
​
1: Object { "abc": "def", "egf":"ghi " }​​

Where as when I print with knockout.toJSON(data) or JSON.stringify(data) it returns

[
  {
    "abc": "def",
    "efg": "hij"
  },
  {
    "abc": "def",
    "efg": "hij"
  }
]

However I am unable to convert the response into array as I want it to be an array.

I even tried JSON.parse on the knockout.JSON(data), JSON.stringify(data), and directly on data but it fails.

What is the best way to convert this to an array.

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

0

JS has primitive data types and Objects,since Array is not a primitive its typeof will return Object.

You can treat your response as an array in your code,no conversion is needed.

Study this SO post for further info and the docs about JS data types

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