My current task involves filtering an array of JSON objects obtained from an API call through my proxy. The API call is made using the Node.js web framework Express.
The API response looks like this:
{
data: [
{
type: "aaa",
name: "Cycle",
id: "c949up9c",
category: ["A","B"]
},
{
type: "bbb",
name: "mobile",
id: "c2rt4Jtu",
category: ["C","D"]
},
...
]
}
In server.js:
function sortDataByID(data) {
return data.filter(function(item) {
return item.id == 'c949up9c';
});
}
app.get('/products', (req, res) => {
const options = {
url: BASE_URL + '/products',
headers: {
'Authorization': 'hgjhgjh',
'Accept': 'application/json'
}
}
request.get(options).pipe(sortDataByID(res));
});
An error message keeps popping up:
TypeError: data.filter is not a function
I'm trying to understand what obvious mistake I might be overlooking here. Any suggestions?