javascript - 如何将javascript中的文本拆分为段落?

标签 javascript

我有以下一段文字:

“嘿,是一些文字吗?

我的名字是一些文字一些文字一些文字一些文字一些文字一些文字一些文字一些文字一些文字一些文字一些文字一些文字一些文字一些文字一些文字一些文字”

我需要分成段落并从 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/

相关文章:

javascript - 部署时使用 npm 包出现 Meteor 错误

javascript - http 到 https - 使浏览器为 http URL 请求相应的 https URL,而不需要编辑所有页面并手动将所有 URL 更改为 https?

javascript - Angular 评估表达式就像它在 HTML 中一样

javascript - 未捕获的类型错误 : Cannot call method 'toLowerCase' of undefined

javascript - 开关盒正则表达式测试

javascript - 正确的javascript继承

javascript - 更改为默认样式

php - 如何设置旋转图像?

javascript - 将 MySQL 与使用 Javascript 的 HTML 页面结合使用

javascript - 如何从db中获取数据