我有一個對象obj1,里面有另一個對象obj2。obj2以相同的方式構建,obj1因此其中將有另一個對象。假設我有 20 個,我正試圖進入其中的每一個以獲取一些數(shù)據(jù)。有沒有辦法創(chuàng)建一個循環(huán),一旦它看到它就進入 obj 內(nèi)部?我嘗試這樣做但沒有運氣。var location;for (var [key, value] of Object.entries(object)) { var type = typeof value; var array = Array.isArray(value); if (typeof value === "object" && array === false && value) { location = key; for (var [a, b] of Object.entries(object[location])) { /*this is where I'm stuck, the location variable doesn't update with the 'path' of every object*/ } }}
我怎樣才能進入嵌套對象結構中的每個對象?
哈士奇WWW
2023-05-25 18:11:42