【发布时间】:2018-08-09 21:23:03
【问题描述】:
我需要遍历一个对象 nodeIDs 并找到特定值的键索引..
private getNodeIndexByID(nodeIDs, id) {
for (const [key, value] of Object.entries(nodeIDs)) {
if (id === value) {
return key;
}
}
}
返回的键是数字 .. 现在我构建了一个新对象,其中保存了键索引
const index_source = this.getNodeIndexByID(nodeIDs, obj.source);
const index_target = this.getNodeIndexByID(nodeIDs, obj.target);
let my_obj = Object.create({}, { source: { value: index_source }, target: { value: index_target } });
out.push(my_obj);
现在out.source 和out.target 的值是typeOf STRING.. 为什么? ..我的意思是,数组索引是数字的..
我错过了什么? .. 我需要它们是数字。
【问题讨论】:
标签: javascript arrays typescript object types