Find items from json array using NodeJS
json, node.js
Solution
The `filter` method is only available on arrays, and it looks like you're calling it on an object (from the outer bracket). You can work around this by looping through the keys:
var arrFound = Object.keys(result).filter(function(key) {
return result[key].server == 'deskes.com';
// to cast back from an array of keys to the object, with just the passing ones
}).reduce(function(obj, key){
obj[key] = result[key];
return obj;
}, {});;
Problem
Am trying to search for particular items from a JSON array and return the items... ``` result = { FF: { server: 'deskes.com', result: 'succes' }, { server: 'cleantarge.com', result: 'Failed' }, { server: 'fance34.com', result: 'success' },{ server: 'deskes.com', result: 'Failed' }, } ``` I have following JSON data. I want to search items based on server I used the code ``` var arrFound = result.filter(function(item) { return item.server == 'deskes.com'; }); But getting TypeError: Object #<Object> has no method 'filter' ``` my resulting JSON after searching the data will be: ``` result = { FF: { server: 'deskes.com', result: 'succes' }, { server: 'deskes.com', result: 'Failed' } } ```