Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

Post Closed as "Not suitable for this site" by connexo, Nguyễn Văn Phong, Mihail Duchev
added 7 characters in body; edited tags
Source Link
Nguyễn Văn Phong
  • 14.2k
  • 19
  • 48
  • 65

I have an array of strings in JavaScript and I want to split them into "paragraphs" by grouping them together based on blank lines. for instance:

["a", "b", "", "c", "", "d", "e", "f"] => [["a", "b"], ["c"], ["d", "e", "f"]]

It's exactly like string.split()string.split() but with an array as the input instead of a string.

Of course, I could write this function myself using a loop or maybe reduce but it sounds like quite a generic function. I'm wondering if there is anything in lodash or similar that could do it.

I have an array of strings in JavaScript and I want to split them into "paragraphs" by grouping them together based on blank lines. for instance:

["a", "b", "", "c", "", "d", "e", "f"] => [["a", "b"], ["c"], ["d", "e", "f"]]

It's exactly like string.split() but with an array as the input instead of a string. Of course I could write this function myself using a loop or maybe reduce but it sounds like quite a generic function. I'm wondering if there is anything in lodash or similar that could do it.

I have an array of strings in JavaScript and I want to split them into "paragraphs" by grouping them together based on blank lines. for instance:

["a", "b", "", "c", "", "d", "e", "f"] => [["a", "b"], ["c"], ["d", "e", "f"]]

It's exactly like string.split() but with an array as the input instead of a string.

Of course, I could write this function myself using a loop or maybe reduce but it sounds like quite a generic function. I'm wondering if there is anything in lodash or similar that could do it.

Source Link
Andy
  • 11.7k
  • 18
  • 79
  • 101

JavaScript - how to split an array based on separator values

I have an array of strings in JavaScript and I want to split them into "paragraphs" by grouping them together based on blank lines. for instance:

["a", "b", "", "c", "", "d", "e", "f"] => [["a", "b"], ["c"], ["d", "e", "f"]]

It's exactly like string.split() but with an array as the input instead of a string. Of course I could write this function myself using a loop or maybe reduce but it sounds like quite a generic function. I'm wondering if there is anything in lodash or similar that could do it.

lang-js

AltStyle によって変換されたページ (->オリジナル) /