合并JSON文件

下面是一段简单地代码 用来减少工作量合并代码

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <script>
let BIG = {};let SM = {};
let BIGObj = JSON.parse(JSON.stringify(BIG))
let SMObj = JSON.parse(JSON.stringify(SM))
for(var key in SMObj) {
  if(!BIGObj[key]){
    BIGObj[key] = SMObj[key]
  }
  if(SMObj[key] instanceof Object){
    for(var a in SMObj[key]){
      if(!BIGObj[key][a]){
        BIGObj[key][a] = SMObj[key][a]
      }
    }
  }
}

console.log(JSON.stringify(BIGObj))
  </script>
</body>
</html>

原文地址:https://www.cnblogs.com/sugartang/p/12101193.html