I have this JSON:
{
"1": {
"PerId":"10900662",
"Name":"Cueball",
"Email":"[email protected]",
"DepartId":"11"
},
"2": {
"PerId":"10900664",
"Name":"Megan",
"MuEmail":"[email protected]",
"DepartId":"11"
},
"3": {
"PerId":"10900665",
"Name":"Beret Guy",
"MuEmail":"[email protected]",
"DepartId":"12"
}
}
Which I want to filter with a specific DepartId
Here's the code I've tested, which is from this Stack Overflow question:
<html>
<body>
Test!
</body>
<script>
var y = JSON.parse('{"1":{"PerId":"10900662","Name":"Cueball","Email":"[email protected]","DepartId":"11"},"2": {"PerId":"10900664","Name":"Megan","MuEmail":"[email protected]","DepartId":"11"},"3": {"PerId":"10900665","Name":"Beret Guy","MuEmail":"[email protected]","DepartId":"12"}}');
var z = y.filter(function (i,n){return n.DepartId == '11'})
</script>
</html>
In this case, y returns an object, but Firefox throws error that y.filter is not a function.
I expected y to return as something like
{
"1": {
"PerId":"10900662",
"Name":"Cueball",
"Email":"[email protected]",
"DepartId":"11"
},
"2": {
"PerId":"10900664",
"Name":"Megan",
"MuEmail":"[email protected]",
"DepartId":"11"
}
}
in the form of JavaScript object. How do I make it work?
filter()can be applied for array not object[ { "PerId":"10900662", "Name":"Cueball", "Email":"[email protected]", "DepartId":"11" }, { "PerId":"10900664", "Name":"Megan", "MuEmail":"[email protected]", "DepartId":"11" } ];