json object from javascript nested array

betterel

I'm using a nested array with the following structure:

arr[0]["id"] = "example0";
arr[0]["name"] = "name0";
arr[1]["id"] = "example1";
arr[1]["name"] = "name1";
arr[2]["id"] = "example2";
arr[2]["name"] = "name2";

now I'm trying to get a nested Json Object from this array

arr{
 {
 id: example0,
 name: name00,
 },
{
 id: example1,
 name: name01,
 },
{
 id: example2,
 name: name02,
 }
}

I tought it would work with JSON.stringify(arr); but it doesen't :( I would be really happy for a solution.

Thank you!

Max

If you are starting out with an array that looks like this, where each subarray's first element is the id and the second element is the name:

const array = [["example0", "name00"], ["example1", "name01"], ["example2", "name02"]]

You first need to map it to an array of Objects.

const arrayOfObjects = array.map((el) => ({
  id: el[0],
  name: el[1]
}))

Then you can call JSON.stringify(arrayOfObjects) to get the JSON.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Simple array object from nested object in javascript

From Javascript

Access nested object JSON array with Javascript

From Dev

How to Convert nested json to array of object in Javascript?

From Dev

Flatten and sort a nested JSON object into an array in javascript

From Dev

javascript create nested JSON array from array

From Dev

getting nested data from JSON array object

From Dev

Create nested object from array javascript

From Dev

Create nested object from array of objects in JavaScript

From Dev

Creating a nested Javascript Object from an array of Strings

From Dev

Create a nested object from Array javascript

From Dev

Created a nested Json structure from an Javascript array

From Dev

Generate nested table from JSON array in javascript

From Dev

In javascript, how do I create a nested array or object from json data?

From Dev

Nested object in Javascript array

From Dev

Loop through nested json array object and sum values javascript

From Dev

Adding data to a nested JSON object with children based on an array - Javascript/REACT

From Dev

Remove entire object from a json array javascript

From Dev

Javascript - delete object from JSON array

From Dev

Javascript - Extracting data from JSON object (array)

From Dev

From nested array to array of object

From Javascript

How to generate a nested array of objects from an source json object

From Dev

How to create nested datatable from JSON array object response

From Dev

Query to extract ids from a deeply nested json array object in Presto

From

GO - Get an array of attribute values from a nested JSON object

From Dev

How to get nested json object and array from retrofit response on android?

From Dev

How to get a nested object from an json parent array in c#

From Dev

how to get a particular object value from nested json array

From Dev

How to get array of checked Values from the nested JSON Object

From Dev

How to find maxium value from nested array Object in Javascript?

Related Related

  1. 1

    Simple array object from nested object in javascript

  2. 2

    Access nested object JSON array with Javascript

  3. 3

    How to Convert nested json to array of object in Javascript?

  4. 4

    Flatten and sort a nested JSON object into an array in javascript

  5. 5

    javascript create nested JSON array from array

  6. 6

    getting nested data from JSON array object

  7. 7

    Create nested object from array javascript

  8. 8

    Create nested object from array of objects in JavaScript

  9. 9

    Creating a nested Javascript Object from an array of Strings

  10. 10

    Create a nested object from Array javascript

  11. 11

    Created a nested Json structure from an Javascript array

  12. 12

    Generate nested table from JSON array in javascript

  13. 13

    In javascript, how do I create a nested array or object from json data?

  14. 14

    Nested object in Javascript array

  15. 15

    Loop through nested json array object and sum values javascript

  16. 16

    Adding data to a nested JSON object with children based on an array - Javascript/REACT

  17. 17

    Remove entire object from a json array javascript

  18. 18

    Javascript - delete object from JSON array

  19. 19

    Javascript - Extracting data from JSON object (array)

  20. 20

    From nested array to array of object

  21. 21

    How to generate a nested array of objects from an source json object

  22. 22

    How to create nested datatable from JSON array object response

  23. 23

    Query to extract ids from a deeply nested json array object in Presto

  24. 24

    GO - Get an array of attribute values from a nested JSON object

  25. 25

    How to get nested json object and array from retrofit response on android?

  26. 26

    How to get a nested object from an json parent array in c#

  27. 27

    how to get a particular object value from nested json array

  28. 28

    How to get array of checked Values from the nested JSON Object

  29. 29

    How to find maxium value from nested array Object in Javascript?

HotTag

Archive