186
rated 0 times
[
193]
[
7]
/ answers: 1 / hits: 122238
/ 8 Years ago, tue, january 24, 2017, 12:00:00
I have a an object jsonRes[0]
containing values which need to be removed based on a condition. The following works to remove null
, missing values and those equal to zero in the stringified object:
function replacer(key, value) {
// Filtering out properties
if (value === null || value === 0 || value === ) {
return undefined;
}
return value;
}
JSON.stringify(jsonRes[0], replacer, t)
However, when I add a condition using the the includes
method, I receive an error:
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
Why is this the case and is there a workaround?
More From » javascript