我有一個(gè)對(duì)象obj1,里面有另一個(gè)對(duì)象obj2。obj2以相同的方式構(gòu)建,obj1因此其中將有另一個(gè)對(duì)象。假設(shè)我有 20 個(gè),我正試圖進(jìn)入其中的每一個(gè)以獲取一些數(shù)據(jù)。有沒(méi)有辦法創(chuàng)建一個(gè)循環(huán),一旦它看到它就進(jìn)入 obj 內(nèi)部?我嘗試這樣做但沒(méi)有運(yùn)氣。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*/ } }}
我怎樣才能進(jìn)入嵌套對(duì)象結(jié)構(gòu)中的每個(gè)對(duì)象?
哈士奇WWW
2023-05-25 18:11:42