I have a search like function that takes in a string. I convert this string to array. The string has comma to distinct between two words.
Ideal format:
search-term-entered = xyz, abc, eee, fff
Now if the user follows my format, I can use split and get my array but what if:
search-term-entered = abc, xyz, , ,,, eee
or search-term-entered = , ,, abc, xyz,eee,fff
or something along these lines
If the user uses some other formatting, how do I get rid of extra white spaces? The only thing is can think of is looping through the array and checking whether for white spaces and removing it. Is there an easier method or way?
This is what my getArray looks like
getArray = search-term-entered.split(", ");