You haven't explained what the problem is. Based on what you
have shown us, you have several problems.
1) The JSON you've shown is an object, but you are trying to call the
Array.prototype.filter[
^] method on it. That method only works for arrays, not objects.
2) You're passing a string value to the
filter
function, when that function expects a callback which will be called on every element of the array. If your source actually was an array, you'd want to call
Array.prototype.includes[
^] instead. But that won't work with the source you've shown, which is a single object.
3) The result of the
filter
function will be a new array with the matching elements from the source array. The result of the
includes
function will be
true
or
false
. Neither of those values will be equal to the string
'undefined'
.
Since your source data appears to be an object, try using the
Object.prototype.hasOwnProperty[
^] function instead:
function filterzip(zip)
{
const rawdata = fs.readFileSync('zip.json');
const mydata = JSON.parse(rawdata);
console.log("parse:", mydata);
return mydata.hasOwnProperty(zip);
};