array.find不适用于Babel [英] array.find doesn't work with Babel
本文介绍了array.find不适用于Babel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Babel发布我的ES2015代码。但是它没有为数组翻译 find
。以下行抛出错误 TypeError:options.find不是函数
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)
推荐答案
使用babel polyfill。
Use babel polyfill.
require("babel/polyfill");
[1, 2, 3].find((x) => x >= 2);
// => 2
或者你可以使用回调。 Array.find(arr,callback)
Or you can use callback. Array.find(arr, callback)
Array.find([ 1, 2, 3 ], (x) => x >= 2);
// => 2
Array.prototype.find
在运行时不起作用·问题#892·babel / babel
Array.prototype.find
doesn't work in the runtime · Issue #892 · babel/babel
这篇关于array.find不适用于Babel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文