Array.prototype.find(criteriaObject, onlyFirst)

Description:

Created a cloned object by itself.

Parameters:

  • criteriaObject
    • Type: Object
  • onlyFirst (Optional)
    • Type: Boolean

NOTE:

In version 1.2.0.0 or above, parameter criteriaObject can be number/string or any other types(EXCEPT function).

Returned Value:

  • Cloned objects which matches the criteria. If onlyFirst is true, return undefined or matched object. Otherwise, return array.

Notice:

The objects in array returned are all cloned objects.

Sample:

var array = [{name: "Apple", weight: 200}, {name: "banana", weight: 50}, {name: "berry", weight: 50}, {name: "Lemon", weight: 180}];
var findResult0 = array.find({ weight: 50 });
var findResult1 = array.find({ weight: 50 }, true);
//Result: findResult0 = [{name: "banana", weight: 50}, {name: "berry", weight: 50}]
//Result: findResult1 = {name: "banana", weight: 50};

var array2 = [1,3,5,7,9,12,15];
var findResult2 = array2.find(9);
var findResult3 = array2.find(8);
var findResult4 = array2.find(9, true);
var findResult5 = array2.find(8, true);
//Result: findResult2 = [9];
//Result: findResult3 = [];
//Result: findResult4 = 9;
//Result: findResult5 = undefined;

Last edited Feb 5, 2013 at 9:07 AM by rynnwang, version 3

Comments

No comments yet.