Place array values in true javascript

0

I have an object, inside that object, I have two properties. The first property is of the boolean type; the second property is of type boolean []. I need to put all the values of the array of the second property in true. I suppose I could do that with a forEach, so that I can go through the array and put true in each array that I go through. But I do not know very well how I can do it, for now, I have this ...

selectCard(i) {
    this.cards[i].valueFlights.forEach(function(check, indexFlight) {

    })
}
    
asked by Jhonatan Cardona Valencia 11.07.2018 в 22:25
source

3 answers

0

You gave yourself the answer to your question, you just need to implement it correctly. Let's say we have a Objeto as you describe, in which the array of boolean has other objects (I guess)

$scope.item = { bool1: true, bool2: [ { val:... }, { val:... } ] }

The correct implementation of the angular.forEach would be:

angular.forEach($scope.item.bool2, function(b){
   b.val = true;
})

If it's not what you need, you let me know colleague

    
answered by 11.07.2018 в 23:06
0

Your contribution is very good; but it's not what I need. I have it like that, I do not know if you can rely on this

$scope.item = { bool1: boolean, bool2: boolean[] }[]

I need that whatever is inside bool2 is true, every value. If I have 20 array indexes, I need each value of those array to be true.

    
answered by 11.07.2018 в 23:30
-1

In the function there is a for that goes through the entire array that is sent to it and each value is assigned as 'true' and the array is returned with all the values in 'true' upon completion.

const arregloConTodosLosBooleanosTrue = this.allTrue(bool2);

$scope.item = {
      bool1: boolean,
      bool2: arregloConTodosLosBooleanosTrue
    };

allTrue(value: boolean[]): boolean[] {
    for (const i of value) {
         i = true;
     }
     return value;
}
    
answered by 16.07.2018 в 08:25