selectedUsers = [];
for (let index = 0; index < this.updateOffer.user_ids.length; index++) {
const element = this.updateOffer.user_ids[index];
this.selectedUsers[index]['id'] = element;
console.log(this.selectedUsers)
}
控制台出现错误
无法设置未定义的属性ID
预期产量
this.selectedUsers = [{ id: 4 }, { id: 6 }];
答案 0 :(得分:2)
您的数组为空,因此您尝试的任何索引都是不确定的
selectedUsers[0]
===> undefined
我认为您正在尝试做什么:
for (let index = 0; index < this.updateOffer.user_ids.length; index++) {
const element = this.updateOffer.user_ids[index];
this.selectedUsers.push({id: element });
console.log(this.selectedUsers)
}