I need to write function that returns 3strings after character ', ' so if there is none or 1 or 2 or 3 to return empty string if ', ' character is found else return 3 strings...i wrote these function but it is very cpu intensive...can be shorter and faster code?
https://jsfiddle.net/1nfyq327/
var str = 'AAA BBB CC., DD EE, FF FF, GG GG, HH HH, II II, JJ JJ, GG GG';
var res = str.substring(0, str.indexOf(', ', str.indexOf(', ', str.indexOf(', ')+1)+1));
console.log(res);
Result is:
AAA BBB CC., DD EE, FF FF
Result is fine but i need faster code because it will execute on low power cpu so speed is very cruicial...
regular expression