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

239
Views
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 answers
Answer question

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 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!