array.find不适用于Babel

Hed*_*dge 9 javascript ecmascript-6 babeljs

我正在使用Babel来编译我的ES2015代码.但它不会转换find为数组.以下行引发错误TypeError: options.find is not a function

let options = [2,23,4]
options.find(options, x => x < 10)
Run Code Online (Sandbox Code Playgroud)

Mat*_*mat 18

使用babel polyfill.

require("babel/polyfill");

[1, 2, 3].find((x) => x >= 2);
// => 2
Run Code Online (Sandbox Code Playgroud)

见:Polyfill·Babel

或者你可以使用回调. Array.find(arr, callback)

Array.find([ 1, 2, 3 ], (x) => x >= 2);
// => 2
Run Code Online (Sandbox Code Playgroud)

Array.prototype.find 在运行时不起作用·问题#892·babel/babel