Documentation for a historical release of Infusion: 1.4
Please view the Infusion Documentation site for the latest documentation, or the Infusion 1.3. Documentation for the previous release.
If you're looking for Fluid Project coordination, design, communication, etc, try the Fluid Project Wiki.

Skip to end of metadata
Go to start of metadata

This functionality is Sneak Peek status. This means that the APIs may change. We welcome your feedback, ideas, and code, but please use caution if you use this new functionality.

fluid.filterKeys(toFilter, keys, exclude)

Accepts an object to be filtered, and a list of keys. Either all keys not present in the list are removed, or only keys present in the list are removed.

fluid.filterKeys(toFilter, keys, exclude);

File name: Fluid.js

Parameters

toFilter (Arrayable or Object) The object to be filtered - this will be modified by the operation.
keys (Array of strings) The list of keys to operate with.
exclude (boolean) If true, the keys listed are removed rather than included. Default is false, i.e. by default, everything is removed but the listed keys.

Return Value

Object the filtered object (the same object that was supplied as toFilter).


Example

fluid.each(addressArray, function (addr, index) {
    fluid.filterKeys(addr, ["city, "country"]);
});

This example processes an array of address objects and strips all but the City and Country information from them. Note that this example is destructive: It directly modifies the original objects in addressArray.

Example: non-destructive

var demographics = [];
fluid.each(addressArray, function (addr, index) {
    demographics.push(fluid.filterKeys(fluid.copy(addr), ["city, "country"]));
});

This example produces a new array of objects containing only the City and Country information in addressArray.

Example

fluid.each(addressArray, function (addr, index) {
    fluid.filterKeys(addr, ["name"], true);
});

This example processes an array of address objects and makes it "anonymous" it by stripping out the name fields. Note that this example is destructive: It directly modifies the original objects in addressArray.

  • No labels