-
慕田峪4524236
function mergeJsonObject(...args) { let resultJsonObject = {}; function jsonObj(jsonObj) { for (let attr in jsonObj) { resultJsonObject[attr] = jsonObj[attr]; } } args.forEach(jsonObj) return resultJsonObject; }
-
精慕HU
function mergeJsonObject(...jsonObjs) { let resultJsonObject = {}; jsonObjs.forEach(function(jsonObj) { for (let attr in jsonObj) { resultJsonObject[attr] = jsonObj[attr]; } }) return resultJsonObject; }更简化一点的,直接Object.assign({}, jsonObj1, jsonObj2)
-
临摹微笑
看以什么规范,如果 ES6 的话可以:function merge(...jsons) { return jsons.reduce((memo, json) => { return Object.assign(memo, json); }, {});}
-
慕容森
function mergeJsonObject(...args) { let resultJsonObject = {} args.map(function(val){ Object.assign(resultJsonObject, val) }) return resultJsonObject}
-
PIPIONE
function mergeJsonObject(jsonObj1, jsonObj2, jsonObj3, jsonObj4, jsonObj5) { let resultJsonObject = {}; let allJson=arguments; for(let index in allJson){ for(let attr in allJson[index]){ resultJsonObject[attr] = allJson[index][attr]; } } return resultJsonObject; }
-
慕仙森
例子参考一下,看看是不是你想要的var aa = function(){for (var i=0; i<arguments.length; i++){ if (typeof (arguments[i]) == "object"){ console.log(arguments[i]) }}}
-
HUWWW
同属性覆盖与否的问题没有解决const mereJsons = () { const args = [...arguments]; return args.reduce((prev, current) => { for(let key in current){ prev[key] = current[key]; } return prev; });}
-
慕码人8056858
function merge() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var merged = {}; function generateObject(target, object) { if (target === void 0) { target = {}; } for (var key in object) { if (object.hasOwnProperty(key)) { target[key] = object[key]; } } return target; } for (var i = 0; i < args.length; i++) { var arg = args[i]; if (arg) { if (isArray(arg)) { for (var i_1 = 0; i_1 < arg.length; i_1++) { var argItem = arg[i_1]; if (isPlainObject(argItem)) { merged = generateObject(merged, argItem); } else if (!isDate(argItem)) { merged[argItem] = argItem; } } } else if (isPlainObject(arg)) { merged = generateObject(merged, arg); } else if (isString(arg) || isNumber(arg)) { merged[arg] = arg; } } } return merged;}