我有一个jsonRes[0]包含需要根据条件删除的值的对象.以下工作原理用于删除null字符串化对象中的缺失值和等于零的值:
function replacer(key, value) {
// Filtering out properties
if (value === null || value === 0 || value === "") {
return undefined;
}
return value;
}
JSON.stringify(jsonRes[0], replacer, "\t")
Run Code Online (Sandbox Code Playgroud)
但是,当我使用该includes方法添加条件时,我收到一个错误:
function replacer(key, value) {
// Filtering out properties
if (value === null || value === 0 || value === "" || value.includes("$")) {
return undefined;
}
return value;
}
Uncaught TypeError: value.includes is not a function
Run Code Online (Sandbox Code Playgroud)
为什么会这样,是否有解决方法?
javascript ×1