Here's a basic example:
for (var fieldName in scope.filters) {
if (!scope.filters.hasOwnProperty(fieldName)) {
alert(fieldName + ": " + scope.filters[fieldName]);
}
}
for..in
will go through all the members of an object.
It's a best practice to always check that the variable is its own member, so you don't pick up any other inherited functions or members. Here is a good explanation and example regarding why you should use hasOwnProperty
.
I just set up an alert, but you can obviously do whatever you need with each fieldName
and its value. Note, in this case, you'll get a lot of alerts.