问题:
I was wondering if there was any way in JavaScript to loop through an object like so.我想知道 JavaScript 中是否有任何方法可以循环遍历这样的对象。
for(var i in myObject) {
// ...
}
But get the name of each property like this.但是像这样获取每个属性的名称。
for(var i in myObject) {
separateObj[myObject[i].name] = myObject[i];
}
I can't seem to find anything like it on Google.我似乎无法在谷歌上找到类似的东西。 They say to pass the names of the variables with them but this is not an option for what I am trying to achieve.他们说要与他们一起传递变量的名称,但这不是我想要实现的选择。
Thanks for any help you can offer.谢谢你的尽心帮助。
解决方案:
参考一: https://en.stackoom.com/question/HsIe参考二: https://stackoom.com/question/HsIe