我有一个对象obj1,里面有另一个对象obj2。
obj2以相同的方式构建,obj1因此其中将有另一个对象。
假设我有 20 个,我正试图进入其中的每一个以获取一些数据。
有没有办法创建一个循环,一旦它看到它就进入 obj 内部?
我尝试这样做但没有运气。
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*/
}
}
}
郎朗坤
相关分类