根据数组 2 中的值设置数组 1 中对象的属性
我这里有两个数组。数组 1 是由一些对象组成的数组数组,如下所示:
var house = [
[
{ x: 50, y: 50, selected: false },
{ x: 150, y: 50, selected: false },
{ x: 250, y: 50, selected: false },
{ x: 350, y: 50, selected: false },
{ x: 450, y: 50, selected: false },
{ x: 550, y: 50, selected: false },
{ x: 650, y: 50, selected: false },
{ x: 750, y: 50, selected: false },
{ x: 850, y: 50, selected: false },
{ x: 950, y: 50, selected: false },
],
[
{ x: 50, y: 130, selected: false },
{ x: 150, y: 130, selected: false },
{ x: 250, y: 130, selected: false },
{ x: 350, y: 130, selected: false },
{ x: 450, y: 130, selected: false },
{ x: 550, y: 130, selected: false },
{ x: 650, y: 130, selected: false },
{ x: 750, y: 130, selected: false },
{ x: 850, y: 130, selected: false },
{ x: 950, y: 130, selected: false },
]
]
数组 2 由一些布尔值组成
var isSelected = [
false,
false,
false,
false,
false,
false,
true,
false,
false,
false,
true,
false,
false,
false,
false,
false,
false,
false,
true,
false
]
我如何迭代这些数组,以便如果数组 2 中的任何元素的值为 true,那么我必须设置数组 1 中相应数组中对象的属性“selected”也设置为 true 吗?
I have two arrays here. Array 1 is an array of arrays consisting of some objects as follows:
var house = [
[
{ x: 50, y: 50, selected: false },
{ x: 150, y: 50, selected: false },
{ x: 250, y: 50, selected: false },
{ x: 350, y: 50, selected: false },
{ x: 450, y: 50, selected: false },
{ x: 550, y: 50, selected: false },
{ x: 650, y: 50, selected: false },
{ x: 750, y: 50, selected: false },
{ x: 850, y: 50, selected: false },
{ x: 950, y: 50, selected: false },
],
[
{ x: 50, y: 130, selected: false },
{ x: 150, y: 130, selected: false },
{ x: 250, y: 130, selected: false },
{ x: 350, y: 130, selected: false },
{ x: 450, y: 130, selected: false },
{ x: 550, y: 130, selected: false },
{ x: 650, y: 130, selected: false },
{ x: 750, y: 130, selected: false },
{ x: 850, y: 130, selected: false },
{ x: 950, y: 130, selected: false },
]
]
And array 2 consisting of some boolean values
var isSelected = [
false,
false,
false,
false,
false,
false,
true,
false,
false,
false,
true,
false,
false,
false,
false,
false,
false,
false,
true,
false
]
How can I iterate over these arrays so that if the value of any element in array 2 is true, then I must set the value of the property "selected" of the object in the corresponding array in array 1 to true as well?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)