According to Is JavaScript a pass-by-reference or pass-by-value language? JavaScript passes string objects by value. Because of that, calling the indexOf
method will trigger copying the content.
In my case, I am parsing a big string to look for data. I heavily use indexOf
to find data. String can big as long as 100-200KB and I could need to call indexOf
up to 1000 times per full scan.
I'm afraid this will cause polluting 'memory' with unnecessarily copied string and could impact performance.
Am I correct in my conclusion? If so, what is the proper way to deal with my task?
Potentially, I could use regular expressions, but at the moment that looks too complex.