Forum Bugs

Javascript string character access returns 'undefined'


I'm currently working on a project involving adding a React component to a page, and I've been tracking down an error that returns `TypeError: undefined value is not an object`.

In the bundled javascript, prince shows the error to occur here:

Upon inspecting the values, I found that the string `event` has `typeof` `"string"`, but `event[0]` is `undefined`, which causes an error when trying to call `toUpperCase()`.

I'm uncertain whether to classify this as a bug or a feature request, as character access is supposed to be included in ES5 (
For anyone else looking to use React, I've elected to render all of my React components server-side, rather than chase down the necessary polyfills, which is now rendering as expected :)

Prince doesn't support the A => B function syntax yet, so I don't think this script will run.
Yes, that is true - though the code we were supplying to prince was a transpiled bundle (using babel) that doesn't transform that string indexing. When I changed that one line to use charAt instead, it rendered fine (with the use of some polyfills as mentioned in another thread).

Thanks for responding! It seems like this might be more of a really-low-priority feature request, as it seems like string indexing is a super nice-to-have when charAt is available.
Hi ehzhang, thanks for doing the analysis - I've added a small test case to the "miscellaneous testcases" repo as a reminder :)
(The test covers two "array-like" ways strings can be used in modern-ish JS engines. @mikeday and co might consider those different features, if they do I should split the test into two.. Also, in disclaimerish mode: I can't predict when devs will get around to implementing something here nor how long it might take.)

Announcement: repos for tests/utils

I've fixed this now and it will be available in the next build.
Super! Thank you :)
The latest build now supports array-like string access. :)