javascript - 将段落拆分为数组 javascript

标签 javascript arrays string split

我有如下代码

return fetch(URI + 'api/brewing/1')
      .then((response) => response.json())
      .then((responseJson) => {

          var parsedResponse = JSON.parse(responseJson["data"][0]["steps"]);
          var stringData = JSON.stringify(parsedResponse);
          })
      .catch((error) => {
        console.error(error);
      });
    }

并获取如下数据

将过滤器在温水浴中浸泡至少五分钟后,将其放入虹吸管顶部组件或料斗的底部,然后卡在料斗玻璃管的底部。底部组件。插入料斗、过滤器和所有部件。

我想将逗号分隔符后面的段落拆分为一个数组,以便我可以循环所有数据。我怎样才能做到这一点?谢谢。

最佳答案

我相信您想用后跟逗号分割字符串:

var s = 'After soaking your filter in a warm water bath for at least five minutes, drop it into the bottom of your siphons top component, or hopper, and hook to the bottom of the hoppers glass tubing.,Fill your siphon bottom component.,Insert the hopper, filter and all.'
s = s.split('.,');
console.log(s);

或:使用正则表达式

var s = 'After soaking your filter in a warm water bath for at least five minutes, drop it into the bottom of your siphons top component, or hopper, and hook to the bottom of the hoppers glass tubing.,Fill your siphon bottom component.,Insert the hopper, filter and all.'
s = s.split(/(?:\.\,)/g);
console.log(s);

关于javascript - 将段落拆分为数组 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55242551/

相关文章:

c++ - 使用二维数组作为一维数组是否正确?可能导致未定义的行为等等?

python - 查找最大值的递归函数返回 0

c# - 在 C# 中将字符串转换为字节数组

c - 关于字符串比较 char* 和数组字符串的区别的解释

javascript - 如何在 vuex 日志中隐藏下一个状态和上一个状态?

javascript - 如何搜索嵌套级别的 JSON 数组

arrays - 找到其和可被 K 整除的最长子数组

javascript - 用 jQuery 替换智能文本

javascript - 有人可以提供如何在 Ember.js 中定义自定义事件的示例吗?

c# - 如何剪切包含 url 的字符串并将其添加到数组