1. JSON.stringify滤除null的属性
let baz = { a : 1, f:null, x:'ddd', b : { c : 2,d:null,e:'null' } }; // 过滤null的值 let replacer = function (key, value) { return value != null ? value: undefined; }; console.log(JSON.stringify(baz, replacer))
2. 两个对象赋值
let arra = { 'aaa':'', 'bbb':'', 'ccc':'' } let arrb = { 'aaa':'111', 'bbb':'222', 'ccc':'333', 'ddd':'444', 'eee':'555' } listAssign(arra,arrb) const listAssign = (arrA, arrB) => Object.keys(arrA).forEach(key => { arrA[key] = arrB[key] || arrA[key]}); listAssign(arra ,arrb )