- 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.
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.