To implement a function today, each item in array a corresponds to each item in array b, and if it corresponds to the checked of array B, add the Ture property, and if it is not found, add the false attribute to the checked of array B.
If there is any write not welcome master private messages to me, the spirit of sharing the Internet.
Idea One
The idea at first was to add the false attribute if the current B[index] is not present checked=true. But there's a drawback to wasting a lot of loops, so I need to look for a way to jump out of the loop.
var a = [1, 2] var b = [{id:1}, {id:2}] for (var i = 0; i < b.length; I++) { for (var n = 0; n < b.length; n++< Span style= "color: #000000") { if (A[i] === b[n].id) {b[n].checked = true } else if (B[n].checked!==true ) {b[n].checked = false }}}console.log (b)
Jump out of the loop method
Explanation: X is the equivalent of marking a mark. Break X If the condition is met; (X's naming itself changes) is equivalent to jumping out of this loop, but the outer I loop is unaffected to continue his loop.
var a = [1, 2]var b = [{id:1}, {Id:2}] for (var i = 0; i < B.len Gth i++) { x: for (var n = 0; n < b.length; n++) { if (a[i ] = = = b[n].id ) {truebreak x; Else { } }}console.log (b)
How JavaScript jumps out of the loop, nesting loops.