Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

240
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda