0

I am getting data in JSON format from an ajax call. I want to convert it into an array to be used in the js script.

 {
  "results":[
  {
     "activity":"A12345"
  },
  {
     "activity":"B12345"
  }]}

Array that I want to have

arr = ["A12345", "B12345"]

I tried the following steps -

var response = JSON.parse(data); 
var arr = response`enter code here`.results; 
var newArr = Object.entries(arr);
alert("New" + Object.values(arr));

The result that I am getting is

[object Object], [object Object]

How can I get the values from these objects and store it in an array. Please help!

  • You dont need to create a *new* object or array after `JSON.parse()` result, because that *is* an object. "Array that I want to have" requires making a new array on requirements. Seems like you have zero code in your question to do this. – mardubbles Apr 09 '22 at 05:02
  • When trying to log the contents of an object or an array, don't concatenate that with a string or log it using `alert()`. Instead, just use `console.log(thingToLog)`. Concatenating it with a string or using `alert()` converts your array to a string, and each object within that into a string, giving your `[object Object]` – Nick Parsons Apr 09 '22 at 05:04

0 Answers0