Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

How do I iterate over this array in array in AngularJS Javascript code:

[[4,5,6,4,8.7]]
share|improve this question
    
on the javascriptside or on the view? – Thomas Zoé Aug 26 at 13:16
    
on the javascript side – blaa Aug 26 at 13:17

An array is an array.

Use Array.prototype.forEach for iteration.

In this case, each item is an array, and therefore you have an inner forEach as well.

Angular also has a method for forEach. It's called angular.forEach.
You can use it if you want to or need to support ancient browsers.

[[4,5,6,4,8.7]].forEach(function(arr){ arr.forEach(function(item){ console.log(item) }) } );

P.s. to avoid the smartass that is going to say that Array.prototype.forEach wont work on IE8, then it doesn't.

share|improve this answer

You can use 'angular.forEach'.

  angular.forEach([[4,5,6,4,8.7]], function(arr){
     angular.forEach(arr, function(value){
       console.log(value);
     })
  });
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.