如何在Angular2中查找推送后数组对象的值



我在angular2.ts文件中有一个数组定义为-

this.dropdownValue=[];

然后我从不同的函数中推送值,比如-

this.dropdownValue.push({ item_text: this.organizationInfo.records[i]._fields[0].end.properties.name });
this.dropdownValue.push({ item_text: this.departmentInfo.records[i]._fields[0].end.properties.name });

控制台语句-

console.log("inside Proceed, this.dropdownValue =", typeof(this.dropdownValue));
console.log("inside Proceed, this.dropdownValue =", this.dropdownValue);
console.log("inside Proceed, this.dropdownValue =", this.dropdownValue[0]);
console.log("inside Proceed, this.dropdownValue =", this.dropdownValue.length);

有几个值的输出是-

typeOf(this.dropdownValue ) = object
this.dropdownValue = 
[
0:{item_text: "IT"}
1:{item_text: "post"}
2:{item_text: "intimationDate"}
3:{item_text: "lossDescription"}
]
this.dropdownValue[0] = undefined
this.dropdownValue.length = 0

我想访问-的值

item_text 

。即将其存储在另一个变量/数组中。

我不能这样做。我也不能访问这些值,找不到它的长度,也找不到特定长度的值PLease帮助

let otherVariable = this.dropdownValue.find(x => x.item_text === 'IT');

我编辑了我的答案,因为我现在不想要你想要的东西。

let otherArray = []; 
for (let obj of this.dropdownValue) {
otherArray.push(obj.item_text);
}

我知道这不是最好的方法,但当我必须做类似的事情时,我总是做

最新更新