Sunday, May 19, 2024
156
rated 0 times [  162] [ 6]  / answers: 1 / hits: 56813  / 6 Years ago, mon, march 12, 2018, 12:00:00

I have got a tslint error to my for loop when I try to resolve it it says to convert to for-of. I have seen many docs but its not helpful.How can I solve the lint error and I cannot do tslint:disable-next-line:prefer-for-of



for (let i = 0; i < this.rows.length; ++i) {
if (!this.rows[i].selected) {
this.selectAllChecked = false;
break;
}
}

More From » visual-studio

 Answers
26

It is asking you to use format like the following. The of keyword loops over the objects in the array instead of looping over the indexes of the array. I'm assuming it is triggering because you are only using the index as a way of getting to the value in the array (which can be cleaned up using the of syntax).



for (let row of this.rows) {
if (!row.selected) {
this.selectAllChecked = false;
break;
}
}


As a note, you can accomplish the same thing using the following one-liner:



this.selectAllChecked = this.rows.every(row => row.selected);

[#54961] Thursday, March 8, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
deonkalvinw

Total Points: 409
Total Questions: 96
Total Answers: 89

Location: Saint Pierre and Miquelon
Member since Sun, Nov 27, 2022
2 Years ago
deonkalvinw questions
Sun, Feb 6, 22, 00:00, 2 Years ago
Tue, Dec 28, 21, 00:00, 2 Years ago
Sun, Aug 22, 21, 00:00, 3 Years ago
Sun, Mar 7, 21, 00:00, 3 Years ago
;