方法一
const arr = [6, 3, 5, 6]; let arrTwo = [ { value: 3, bool: false }, { value: 1, bool: false }, { value: 2, bool: false }, { value: 4, bool: false }, { value: 7, bool: false }, { value: 6, bool: false }, ]; function method(param) { for (let i = 0; i < arrTwo.length; i += 1) { if (param === arrTwo[i].value) { arrTwo[i].bool = true; } else { } } } arr.forEach((item) => { method(item); }); console.log(arrTwo); |