1
How to set a value for a property in all list indices without looping?
object:
var objeto = {
nome: "",
ativo: false
}
list:
[{"nome": "Carlos","ativo":false},{"nome": "Joao","ativo":false}]
In this example, everyone should have the active property changed to true.
The way it solves:
for (var i in lista) {
lista[i].ativo = true;
}
Is there any way to avoid that loop, make that change all at once? because in actual application the object is more complex and has many records, leaving this method slow.
Without making a loop should not give, maybe it is possible to optimize this loop to be faster. It doesn’t make much sense to be able to access all the items on a list without having to go through them all.
– Jéf Bueno
If you don’t make one loop, someone will be doing behind, in case there is a library that does this.
– BrTkCa