JSON.stringify() 处理数据时 undefined和null 的不同 鞋子 2023-02-12 541 阅读1分钟 null和undefined 经过JSON.stringify() 处理后会有不同的结果 undefined则排除成员。根对象的键是一个空字符串:"" ;所以我们需要将undefined 替换为null const replacer = (key,val) => typeof val === 'undefined' ? null : val; const undefinedToNull = (arg) => JSON.parse(JSON.stringify(arg,replacer));