search in a for in angularjs

0

How about, I have this array:

which corresponds to the total purchase according to the order, in this case by a for how can I get to that value:

     for (var i = 0; i < total.length; i++) {

     var totaldesayuno = total[i].totaldesayuno;
     var totalcafe = total[i].totalcafe;
     var totalsandwich = total[i].totalsandwich;
     var totaldulce = total[i].totaldulce;

  }

I need to ask which is the one that has the value to be able to show it in front with $scope

    
asked by Hernan Humaña 20.01.2017 в 23:18
source

1 answer

0

Run each value in total[i] and create a condition to check which is not null (This only works if in all cases only 1 item will get the value)

forEach (total[i], function(value, key))
    if (value != null)
        return value;

This under your forloop, in key you have the name of the object (total breakfast, totalcafe, etc ...) is not angularJs, but this should work. It would not be return value, you would use that of scope, or whatever, but the logic is as I put it to you, you have your modifications and I hope it works for you.

    
answered by 21.01.2017 в 01:17