0

I started node repl and typed this in

> 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)

What is wrong here? Why would an array object does not have the find method? Isn't it the same as here?

3
  • 1
    Run Node with ES6 ("Harmony") features enabled. Commented Jan 29, 2015 at 4:58
  • is it just node --harmony? but it still does not work. Commented Jan 29, 2015 at 5:05
  • Well I thought so but now somebody says I'm wrong :( It may not be supported yet. Commented Jan 29, 2015 at 5:06

1 Answer 1

1

V8 did not realize .find() array method for now (see source). So node.js and io.js do not support it. See compatibility table

Sign up to request clarification or add additional context in comments.

3 Comments

It does if you invoke it with --harmony
@Pointy no, try it youself. I think v8 does not support find() for now, but can be wrong at this point.
Oh. Weird. It supports lots of other ES6 stuff; .find() certainly doesn't seem exotic.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.