gpt4 book ai didi

javascript - 为什么javascript中的对象没有find方法?

转载 作者:行者123 更新时间:2023-12-03 10:57:44 28 4
gpt4 key购买 nike

我启动了 node repl 并输入了此内容

> function isPrime(element, index, array) {
... var start = 2;
... while (start <= Math.sqrt(element)) {
..... if (element % start++ < 1) {
....... return false;
....... }
..... }
... return element > 1;
... }
undefined
> [4, 6, 8, 12].find(isPrime)
TypeError: Object 4,6,8,12 has no method 'find'
at repl:1:16
at REPLServer.self.eval (repl.js:110:21)
at Interface.<anonymous> (repl.js:239:12)
at Interface.EventEmitter.emit (events.js:95:17)
at Interface._onLine (readline.js:202:10)
at Interface._line (readline.js:531:8)
at Interface._ttyWrite (readline.js:760:14)
at ReadStream.onkeypress (readline.js:99:10)
at ReadStream.EventEmitter.emit (events.js:98:17)
at emitKey (readline.js:1095:12)

这里出了什么问题?为什么数组对象没有 find 方法?不是和here一样吗?

最佳答案

V8 目前没有实现 .find() 数组方法(参见 source )。所以 node.jsio.js 不支持它。请参阅compatibility table

关于javascript - 为什么javascript中的对象没有find方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28207287/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com