Those who have Chrome 30.0.1599.14 dev seem to be gifted of this new function:
String(Array.prototype.find); // "function find() { [native code] }"
However, I haven't found any reference for this addition. From my tests it seems that it accepts arguments a-la some, every and so on:
array.some(callback[, thisObject]);
and callback is the usual callback function of that kind:
function([item[, index[, array]]]) {
...
}
The function is expected to return true when the "right" item is passed, so that item becomes the value returned by find. For example:
Array.prototype.slice.call(document.getElementsByTagName("*"))
.find(function(element) {return element.id === "content";});
It's an odd way to re-define document.getElementById, except when the item isn't found find returns undefined instead of null.
It could be nice if this function could accept an initial index, or if there could be a dual function like lastFind that parses the array from the end.
Is there anybody who's already seen this function and can tell me where I can find its spec?
It is ECMA Script 6. Here's an HTML version of the ES6 spec. Here's the specific section for Array.prototype.find().
Update: also, the Chromium bug for Array.prototype.find implementation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With