獲取對象的屬性名稱 - Getting the object's property name

問題:

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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章