GarethFrazer GarethFrazer - 7 months ago 17
Javascript Question

Get all objects from Array in Angular Scope

I am trying to get all objects within an array from a scope in angular. I am using jQuery to get the array but I'm not sure how to get each object from the array without having to define it like [0].

angular.element("#scopes").scope().fixtures;


This gives me:

Array[380]


Which I can then select from but I need to get them all in one go.

Thanks.

Answer

This will iterate over each item in the array allowing you to do what you want with it. $.each Docs

$.each(angular.element("#scopes").scope().fixtures, function (index, element) {
  // do what you want - as per your comments...
  console.log("Element: " + index);
  console.log("Status: " + element.status);
  console.log("________________________________");
});
Comments