js比較兩個對象的差別並返回


    function funDifference(object, other) {
      let diff = {}
      let vChildren
      for (var key in object) {
        if (typeof object[key] === 'object' && typeof other[key] === 'object' && object[key] && other[key]) {
          vChildren = funDifference(object[key], other[key])
          if (Object.keys(vChildren).length > 0) {
            diff[key] = vChildren
          }
        } else if (object[key] !== other[key]) {
          diff[key] = object[key]
        }
      }
      if (JSON.stringify(diff) == '{}') {
        return null
      } else {
        return diff
      }
    }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM