0

I have a table name Post, the function below Posts.query give me all the post and stock them in a variable postsATraiter.

Posts.query({}, function() {
    $scope.postsATraiter = $scope.posts;
});

This works fine I can do a :

console.log($scope.postsATraiter.length);

This give me the number of post who are in my table, but now I would like to display the value inside my postsATraiter ( date for exemple ).

I try this :

console.log(postsATraiter.valueOf(1).date);

This is not working, I think valueOf is not the correct function for get one element, but I don't know which one I need to use. Thanks for answer

2
  • Is postsATraiter an array?? Commented Jan 13, 2016 at 16:35
  • If so just access the array with [1] for example. Commented Jan 13, 2016 at 16:37

1 Answer 1

1

You can iterate through the array of objects and print the needed property value as

$scope.postsATraiter.forEach(function(element) {
    console.log(element.date);
});

The function is called for each object in the array.

To access the first element's date property you can simply do

$scope.postsATraiter[0].date
Sign up to request clarification or add additional context in comments.

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.