Re: JSLint does not allow commas inside of arrays
- --- In firstname.lastname@example.org, "douglascrockford" <douglas@...> wrote:
> JSLint will now continue after an extra comma in an array literal.
> But I still recommend that you fix your code.
Actually, I would never write such garrish code (normally). Allow me to explain my use case (and how I found out about this):
I have a function that converts a string into an array. For instance, the string "[0, 1, 2, 3, 4]" gets converted into the array [0, 1, 2, 3, 4].
It needs to be able to handle a variety of situations; strings, booleans, numbers, etc. So I wrote a bunch of unit tests to verify that it is working properly. They have already helped me catch a couple regressions.
The goal of the function was to convert the string as accurately as possible, so if you pass in the string "[,,,]" you should get back the array [,,,]. I had a unit test that verified that commas in the string would properly get converted to commas in the array.
When running these unit tests in JSLint, I stumbled upon the error, hence this post.
- --- In email@example.com, Paul Novitski <paul@...> wrote:
>You are quite right. I meant to say "There are times where you wish to leave the value of particular indices of an array as undefined."
> I imagine this was just a typo but just in case it wasn't I'll point
> out that it's not the indices here that are undefined, it's the
> values. The indices for the array above are consecutive integers 0-6.
> Paul Novitski
> Juniper Webcraft Ltd.