filter

When this method is used on a set, then the return value will be a new set.

This function does not generate an event.

Function

set.filter(callback)

Arguments

The callback argument must be a closure which input values depend on the type the method is called on.

Iterable Arguments Description
set thing, id Iterate over things in the set. Both thing and id are optional.

Return value

A new set with the elements that pass the test. If no elements pass the test, an empty set will be returned.

Example

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"
    }
]