0

I have code that returns an array in json format but I want it to be under "data": So right now, it shows as:

"["newDate": 'test'": 'test',"attendees": 'test,"name": 'Foo']"

How do I get it as: "{ data: ["newDate": 'test'": 'test',"attendees": 'test,"name": 'Foo'] }"

let countries = [];
    for (x in newObj) {
        countries.push({
            "newDate": newObj[x][0],
            "count": getDates()[x].length,
            "attendees": getDates()[x],
            "name": x
        })
    }
return JSON.stringify(countries);
2
  • 2
    Wrap the return (countries) in an object with the key data? Commented Sep 23, 2020 at 12:21
  • try JSON.stringify({data: countries}); Commented Sep 23, 2020 at 12:22

2 Answers 2

1
JSON.stringify({data:countries});
Sign up to request clarification or add additional context in comments.

1 Comment

Please post explenations with your answer, even for simple ones like these so the OP understand where they went wrong.
0

You need to use this argument:

JSON.stringify({ data: countries });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.