fluid.filterKeys(toFilter, keys, exclude) Section |
---|
Column |
---|
| 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. Code Block |
---|
| javascript |
---|
| javascript |
---|
bgColor | white |
---|
borderStyle | nonejavascript |
---|
|
fluid.filterKeys(toFilter, keys, exclude);
|
File name: Fluid.js Parameters Span |
---|
| 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 Span |
---|
| Object | the filtered object (the same object that was supplied as toFilter ). |
|
|
| Example Code Block |
---|
|
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 Code Block |
---|
|
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 Code Block |
---|
|
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 . |