data.forEach(function (object, index) {
console.debug(object.output);
//this consists of array object like below
//how to loop through these using higher order function so that I don't have to use for loop
[0]{"id": "453", "name":"keren"},
[1]{"id": "453", "name":"amy"},
[2]{"id": "453", "name":"samta"}
我得到的错误说,object.output不是一个函数。 我喜欢高阶函数的原因是为了避免嵌套for循环获取数组的长度,然后循环通过主数组内的嵌套数组。如何循环更高阶的函数?
即使我使用传统的for循环,我也无法获得object.output的长度。
这里面有什么记录:data.forEach(function (object, index) {....}
现在,我该怎么办环通输出,每一个对象?
基于怪异answwer编辑:
data.forEach(function (object, index) {
Object.keys(object).forEach(function (key){
if (typeof object[key] == 'object') {
console.debug(object[key]);
//how to iterate through each object here?
object[key].forEach(function(x){
console.debug(x);
});
}
});
});
是'output'应该的属性你正在使用的对象?如果是这样,什么资源证实了这一点? –
@SamOnela,'output'是包含对象数组的对象 – 112233
object.forEach(function(obj){console.log(obj);});这会给你数组中的对象 – Geeky