Nested array within an Array Object
See original GitHub issueI was hoping to figure out how I can have an array or an array object within another array object.
my desired output
{
"staff": [{
"name": "john doe",
"another_array": [
"something",
"something2"
],
"array_obj": [{
"title": "something",
"desc": "foobar"
}]
}]
}
I’ve tried something like
<input name="staff[]another_array[]">
and something like…
<input name="staff[]array_obj[][title]">
But none of the above works. It doesnt appear you can have nested arrays. Is this true?
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
How does Nested Array work in JavaScript? - eduCBA
Nested Array in JavaScript is defined as Array (Outer array) within another array (inner array). An Array can have one or more inner...
Read more >Understanding Nested Arrays in JavaScript
JavaScript lets us create arrays inside array called Nested Arrays. Nested Arrays have one or many arrays as the element of an array....
Read more >Group objects inside the nested array JavaScript - Tutorialspoint
Our job is to prepare an object with key as key of objects and value being an array that contains all the values...
Read more >Understanding Nested Arrays in JavaScript | by Sanchitha SR
Understanding Nested Arrays in JavaScript ... An array is an ordered collection of values: each value is called an element, and each element...
Read more >How to access a nested array of objects in JavaScript | Code
You can access a nested array of objects either using dot notation or bracket notation. JavaScript has only one data type which can...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Using the
array[][nestedObjKey][]
syntax works, but it will add keys to the object only if the key does not exist, and create new object elements if the key does not exist… Kind of magic behavior that may work great or be super-confusing.To avoid confusion, I recommend explicitly specifying the array indexes (use
[0]
,[1]
,[2]
, … instead of just[]
):And then use serializeJSON with the option useIntKeysAsArrayIndex:
This way you get exactly what you would expect:
@randallmlough If you don’t mind ,would you like to tell me how can you get that result ? My output in Chrome is not tidy as your result.