Filter Active Users in n8n Code Node
An API returns a list of users. You only want to pass forward users where 'status' is equal to 'active'.
Incoming Payload / Data:
[
{ "name": "David", "status": "active" },
{ "name": "Emma", "status": "inactive" }
]
βοΈ Your expression is executed against test data β any correct solution passes. +20 XP
β Solution & explanation
Output: [{ "name": "David", "status": "active" }]
Array.filter() keeps only the items where the callback returns true. In the n8n Code node every item wraps its data in .json, so the field is item.json.status.π‘ Pro tip: Use strict equality (===) so you don't accidentally match a different type. For no-code filtering, the Filter node does the same job without writing JavaScript.
Also accepted: item.json.status=='active'