I am a bit new into programming and I have this function:
function filterJSON(json, key, value) {
var result = [];
json.forEach(function(val,idx,arr){
if(val[key] == value){
result.push(val)
}
})
My problem is the understanding of the second part:
json.forEach(function(val,idx,arr){
if(val[key] == value){
result.push(val)
}
})
We got in this case val
as an argument and in the if statement we use the term val[key]
. So does this means, the argument val
is an array? And at the end, we push a whole array into the empty array named result
?
Thanks a lot!