我有以下一段文字:
“嘿,是一些文字吗?
我的名字是一些文字一些文字一些文字一些文字一些文字一些文字一些文字一些文字一些文字一些文字一些文字一些文字一些文字一些文字一些文字一些文字”
我需要分成段落并从 3 个元素获取数组(上面有 3 个段落)
最佳答案
这很简单。您使用 String.prototype.split
在你的字符串上运行。
您可以在 \n\n
上拆分它。
let text=`Hey is some text some text?
You are some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text
My name is some text some text some text some text some text some text some text some text some text some text some text some text some text some text`//declare variable
let split=text.split('\n\n') //split up
//logging every new line:
split.forEach(function(item){console.log(item)})
关于javascript - 如何将javascript中的文本拆分为段落?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67572599/