Skip to content
Advertisement

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” The HTML: The JS:

Split large string in n-size chunks in JavaScript

I would like to split a very large string (let’s say, 10,000 characters) into N-size chunks. What would be the best way in terms of performance to do this? For instance: “1234567890” split by 2 would become [“12”, “34”, “56”, “78”, “90”]. Would something like this be possible using String.prototype.match and if so, would that be the best way to

JavaScript: Split array into individual variables

Considering this data structure: Looping through each vehicles item, is there a way to reassign the array elements to individual variables all in one shot, something like: … I’m trying to get away from doing: Just curious since this type of thing is available in other programming languages. Thanks! Answer Now it is possible using ES6’s Array Destructuring. As from

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 of the

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” the output should be “hello”. How can I do this in JavaScript?

Advertisement