I'm transpiling my ES2015 code using Babel. However it doesn't translate find
for Arrays. The following line throws the error TypeError: options.find is not a function
let options = [2,23,4]
options.find(options, x => x < 10)
Use babel polyfill.
require("babel/polyfill");
[1, 2, 3].find((x) => x >= 2);
// => 2
See: Polyfill · Babel
Or you can use callback. Array.find(arr, callback)
Array.find([ 1, 2, 3 ], (x) => x >= 2);
// => 2
Array.prototype.find
doesn't work in the runtime · Issue #892 · babel/babel
In newer versions it's
import 'babel-polyfill'
source: Babel Docs
Or if you're using ES6 imports already
import 'babel/polyfill';
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