Skip to content

Tag: split

Splitting a string before finding longest word

I have read a few different posts on this so I am sorry to ask this again but none seemed to solve my issue. I’m trying to draw out the length of the longest word in a string, that is coming from HTML. All I can get is, “Uncaught TypeError: Cannot read property ‘split’ of undefined&#82…

How can I convert a comma-separated string to an array?

I have a comma-separated string that I want to convert into an array, so I can loop through it. Is there anything built-in to do this? For example, I have this string Now I want to split this by the comma, and then store it in an array. Answer MDN reference, mostly helpful for the possibly unexpected behavior…

Getting the last element of a split string array

I need to get the last element of a split array with multiple separators. The separators are commas and space. If there are no separators it should return the original string. If the string is “how,are you doing, today?” it should return “today?” If the input were “hello” t…