有一个物体
var abb = {"DATA":[{"A":"122","B":"444","C":"fff"},
{"A":"1223","B":"6666","C":"s"},
{"A":"555","B":"76666","C":"pod"},
{"A":"7676","B":"34345","C":""},
{"A":"54553","B":"2325555","C":""}]};
这是我的代码
var recursive_f =function(a){
if(a.length > 0){
console.log(a[0]);
recursive_f(a.slice(1));
}
}
recursive_f(abb.DATA);
我的结果是这样的 my result
但是我想要这个 answer
答案 0 :(得分:3)
a[0]
是一个对象,并且您希望该对象的所有值都在数组中。为此使用Object.values。
var abb = {"DATA":[{"SLIP_NO":"RE2018070006","IO_DATE":"2018-07-11 00:00:00.0","REMARK":"185"},{"SLIP_NO":"RE2012060003","IO_DATE":"2012-06-06 00:00:00.0","REMARK":""},{"SLIP_NO":"RE2012060003","IO_DATE":"2012-06-06 00:00:00.0","REMARK":""},{"SLIP_NO":"RE2018030028","IO_DATE":"2018-03-14 00:00:00.0","REMARK":""},{"SLIP_NO":"RE2018030029","IO_DATE":"2018-03-14 00:00:00.0","REMARK":""}]};
var recursive_f = function(a) {
if (a.length > 0) {
console.log(Object.values(a[0]));
recursive_f(a.slice(1));
}
}
recursive_f(abb.DATA);
注意:我假设您已经构建了此功能来测试某些东西。因为要遍历数组,应使用Array.forEach
或loop
的a。