The function returns a new set with things that pass the test.
This function does not generate a change.
set.filter(callback)
Argument | Type | Description |
---|---|---|
callback | closure (required) | Closure to execute on each value. |
Explanation of the callback argument:
Iterable | Arguments | Description |
---|---|---|
set | thing, Id | Iterate over things in the set. Both thing and id are optional. |
A new set
with the things that pass the test.
If no items passed the test, an empty set will be returned.
This code shows an example using filter():
users = set({name: 'Iris', age: 6}, {name: 'Sasha', age: 34});
/*
* Return all users with name 'Iris'.
*/
users.filter(|user| (user.name == 'Iris'));
Return value in JSON format
[
{
"age": 6,
"name": "Iris"
}
]