FrenchyNYC
FrenchyNYC

Reputation: 337

How to grab a certain data from Array?

I am new to Javascript / Ionic so I try to wrap my head around different concepts.

I have a function that retrieve the users like this :

$timeout(function(){
              $scope.users = snapshot1.val();
              console.log($scope.users);
              })

Which gives me the information in the console.

Now, I would like to isolate the field "name" but when I do :

snapshot1.val().name;

It does not work. Is there a way to grab only a specific field ?

Upvotes: 0

Views: 30

Answers (1)

Jonas Wilms
Jonas Wilms

Reputation: 138557

console.log(snapshot1.val().map(el=>el.name));

If its really an Array, you can generate a new Array containing just the name property using Array.prototype.map...

Upvotes: 2

Related Questions