Cannot read property "length" of undefined
See original GitHub issueIf you pass a regExp as second argument in function reactStringReplace
you can get error like: Cannot read property "length" of undefined
. I think thiss is caused by the work of vanilla replace
method.
For example, this code give us an error (it’s cyrillic): const str = ‘Справка Форма Ф9’; const re = /(справка[а-я].?(по)? форм[а-я] [ф|Ф]\d)/gi console.log(str.split(re)); // [“”, “Справка Форма Ф9”, undefined, “”]
So you cannot get length proprty of undefined. And this error will crush you page.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
TypeError: Cannot read property 'length' of Undefined in JS
The "Cannot read property 'length' of undefined" error occurs when accessing the length property on an undefined value. To solve the error, ...
Read more >Typeerror: Cannot Read Property 'length' of Undefined
A typeerror length of undefined can indicate that the actual type of an operand is different from the expected type. This error can...
Read more >[SOLVED] Cannot Read Property 'length' of Undefined in JS
4 Quick Fixes for the “Cannot Read Property 'length' of Undefined” Error in JavaScript · 1. Use an if Statement · 2. Use...
Read more >Cannot read property length of undefined - Stack Overflow
The error means that what ever element is returned by getElementById('WallSearch') , it does not have a value property. Every form field has...
Read more >Cannot read property 'length' of undefined - Treehouse
Cannot read property 'length' of undefined. Hi, i doing "Using Logic in Pug". I followed along with the video and checked another studens ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Agreed, I pushed a change that should fix this. Thanks for raising the issue. Will publish in next version.
@iansinnott Thanks for remark. You are right, there was an issue with our regex however, IMO, in order to prevent error throws, better to add the solution above(or in existed PR), or to add try catch to the code(maybe return error with ‘wrong regex provided’ or something similar)