是否有一种方法可以递归循环遍历JS / jQuery对象的所有嵌套属性?
例如,给定此对象
var x = { 'name': 'a','level': 1,'children': [{ 'name': 'b','level': 2,'children': [{ 'name': 'c','level': 3,'children': [{ ... }] }]},... }] }
我怎么能无限制地圈出名为’a’的对象和他们的孩子,’b’和他们的孩子,’c’和他们的孩子?
@R_403_323@
递归方法看起来最好,如下所示:
function recursiveIteration(object) { for (var property in object) { if (object.hasOwnProperty(property)) { if (typeof object[property] == "object"){ recursiveIteration(object[property]); }else{ //found a property which is not an object,check for your conditions here } } } }