0

Randomly hanging script(JS)?

I was trying to split a text and I couldn't find any functions so I tried to write one. The problem is whenever I call the function, script hangs, then gets out of memory. The most intresting part is, if I try to write that function to console, it works normal. Here is code ( the line with "*" is where script hangs ) function split(textedlol,searchdat){ textedlol = new String(textedlol); textedlol = eval(textedlol); var done = []; var finddis; do{ finddis = textedlol.indexOf(searchdat); done.push(textedlol.substring(0,finddis - 1)); textedlol = textedlol.substr(finddis + 1); } while(textedlol != "" || finddis != "-1"); return done; } If there is any other functions that I can use please tell me.

14th Apr 2018, 8:18 PM
Arda Aydın
Arda Aydın - avatar
2 ответов
+ 5
You need not define your own function, as there's one already available for you. In case you have not checked this yet: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split
15th Apr 2018, 8:15 AM
Dev
Dev - avatar
0
Alright I'll try to use it, but I don't understand why it hangs. Also I forgot to tag the line, it hangs at "finddis = textedlol.indexOf(searchdat)"
15th Apr 2018, 2:11 PM
Arda Aydın
Arda Aydın - avatar