Join is not a function

Evgenij Reznik picture Evgenij Reznik · Oct 31, 2015 · Viewed 20.1k times · Source

I'm playing around with PEG.js

start = keyword

keyword = a:[a-z]? {return a.join("");}

Why am I getting here the error:

a.join is not a function

when I enter a valid string like abc?

Answer

misantronic picture misantronic · Oct 31, 2015

join() is an array-function, you cannot use it on a string: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/join