I have a problem to filter the data, this is my data:
var data = {
CustomerInfo: [{ id : 3, name: "c" }],
detail: {company: "Google"},
location: {country: "Italy"},
CustomerInfo2: [{ id : 4, name: "d" }]
};
and I want to print each name that is not the object format (data[x][x] !== 'object'). for example, print just the "company" and "country".
here is my code:
var dataFiltered = Object.keys(data).filter(function(parent){
return Object.keys(data[parent]).filter(function(child){
return typeof data[parent][child] !== 'object';
});
}).reduce(function(prev, child) {
console.log(prev + " >>> " + data[child]);
});
I am kind of messed up with the filter inside the filter.
at the end I want this result:
company >>> Google
country >>> Italy
filtercallback is expected to return a boolean. Not an array like your innerfilterArray.isArray?foo[bar]Array.isArrayjust fine.