zoukankan      html  css  js  c++  java
  • 递归与非递归遍历

    var properties = [];
    function getProps(obj) {
        if (typeof target == 'object') {
            for (var key in obj) {
                if (obj.hasOwnProperty(key)) {
                    properties.push(key);
                    eachProp(obj[key]);
                }
            }
        }
    }
    
    function getProps2(obj) {
        var props = [];
        var queue = [obj];
        var target;
    
        while(target = queue.shift()) {
            if (target && target.constructor === Object) {
                for (var key in target) {
                    props.push(key);
                    queue.push(target[key]);
                }
            }
        }
    
        return props;
    }
  • 相关阅读:
    053335
    053334
    053333
    053332
    053331
    053330
    053329
    053328
    053327
    053326
  • 原文地址:https://www.cnblogs.com/zhoulingfeng/p/7089857.html
Copyright © 2011-2022 走看看