Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.
oatkiller edited this page Sep 13, 2010 · 6 revisions

Find acts on an object or array. it iterates over each element, testing them with a fn you provide. find returns the first element that passes the test:

(function () {

// find the tea object
[
	{name: 'apple', type: 'fruit'},
	{name: 'banana', type: 'fruit'},
	{name: 'lemonade', type: 'beverage'},
	{name: 'tea', type: 'beverage'}
][o.find](function (edible) {
	return edible.name === 'tea';
});
// returns {name: 'tea', type: 'beverage'}

})();
Clone this wiki locally