Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looping through a multidimensional array in Handlebars.js

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?

like image 787
user1179321 Avatar asked Mar 17 '13 17:03

user1179321


People also ask

How do you loop through a multidimensional array?

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.

Does JS support multi dimensional 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.

How do you declare multidimensional array in JavaScript explain with an example?

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 JavaScript?

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.


1 Answers

You'd have to loop 2 times:

{{#each userSurvey}}   {{#each this}}     {{ this }}   {{/each}} {{/each}} 
like image 175
Simon Boudrias Avatar answered Sep 17 '22 05:09

Simon Boudrias