How to convert Javascript parenthese to access array to square bracket?

It can happen in old project that array objet are accessed with parentheses instead of square bracket.

For example, MyArray[0] is in fact the first element of an array in Javascript. But, IE let you use MyArray(0). This is not a good practice and other browsers doesn’t accept this syntax.

To convert easily, you can use a Regex expression. In my case, the array name was InTran.

InTran\({(.+)}\) //Find

InTran\[\1\] //Replace

The curly bracket is required by Visual Studio to have a backreference but is not required by all Regex tool.

If you like my article, think to buy my annual book, professionally edited by a proofreader. directly from me or on Amazon. I also wrote a TypeScript book called Holistic TypeScript

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.