1

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

[[4,5,6,4,8.7]]
2
  • on the javascriptside or on the view? Commented Aug 26, 2016 at 13:16
  • on the javascript side Commented Aug 26, 2016 at 13:17

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

You can use 'angular.forEach'.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.