Which is the easiest way to loop over this array in JS?
[[45,67,4],[7.8,6.8,56],[8,7,8.7]]
Thanks in advance!
In html with angular:
<!-- assuming myArray is a variable on $scope object -->
<div ng-repeat="innerArray in myArray">
<div ng-repeat="value in innerArray">
{{ value }}
</div>
</div>
Or in js, use for-loops:
var myArray = [[45,67,4],[7.8,6.8,56],[8,7,8.7]];
for (var i = 0; i < myArray.length; i++) {
var innerArray = myArray[i];
// loop through inner array
for (var j = 0; j < innerArray.length; j++) {
var myValue = innerArray[j];
console.log(myValue);
}
}
<div ng-repeat="value in innerArray"> during iterationBy using ng-repeat:
<div ng-repeat="subArray in masterArray">
<div ng-repeat="element in subArray">
{{element}}
</div>
</div>
will yield as result 45 67 4 7.8 6.8 56 8 7 8.7
In javascript (angularjs it's not necessary here)
masterArray.forEach(function(subArray) {
subArray.forEach(function(element) {
console.log(element);
});
});