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

时间:2015-01-29 04:56:27

标签: javascript node.js

我开始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相同?

1 个答案:

答案 0 :(得分:1)

V8目前尚未实现.find()数组方法(请参阅source)。因此node.jsio.js不支持它。见compatibility table