I have the server passing back this JSON and I'm not sure how to loop through a 2-dimensional array in Handlebars.
"userSurvey":[[1],[2],[3]]
I know to use {{#each userSurvey}}
but then how would I go about do the arrays inside the usersurvey
object?
Looping through multidimensional arrays Just as with regular, single-dimensional arrays, you can use foreach to loop through multidimensional arrays. To do this, you need to create nested foreach loops — that is, one loop inside another: The outer loop reads each element in the top-level array.
Javascript has no inbuilt support for multidimensional arrays, however the language is flexible enough that you can emulate this behaviour easily by populating your arrays with separate arrays, creating a multi-level structure.
Method 1: 1st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
Which of the following is the correct way to declare a multidimensional array in Java? Explanation: The syntax to declare multidimensional array in java is either int[][] arr; or int arr[][]; 5.
You'd have to loop 2 times:
{{#each userSurvey}} {{#each this}} {{ this }} {{/each}} {{/each}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With