- Print
- DarkLight
- PDF
Article summary
Did you find this summary helpful?
Thank you for your feedback
Description
Loops through each item in the passed array and returns the item that has a range that the specified value falls within.
Input Parameters
Name | Type | Required | Description |
---|---|---|---|
array | Any | Yes | Array of Json objects |
attrRange1 | Text | Yes | Property name whose numeric value indicates the start of the range |
attrRange2 | Text | Yes | Property name whose numeric value indicates the end of the range |
value | Number | Yes | Numeric value that is checked whether or not it is within each item's numeric range |
Returns
Type: Any
Returns the Json object from the passed array whose range the specified value falls within.
Examples
var items = [
{ "value1": 0, "value2": 19, "color": "Red" },
{ "value1": 20, "value2": 29, "color": "Green" },
{ "value1": 30, "value2": 39, "color": "Blue" },
{ "value1": 40, "value2": 49, "color": "Yellow" },
{ "value1": 50, "value2": 100, "color": "Orange" }
];
// find the item in the array whose range 32 falls within
// note: the entire object for 'Blue' is returned
var item = tools.findByRange(items, "value1", "value2", 32);
Remarks
Use this function when you have an array of Json objects and you want to find a particular object based on whether or not a specified value falls within a numeric range identified by two specified properties that exist on every object in the array.