разделить абзац на массив javascript - PullRequest
0 голосов
/ 19 марта 2019

У меня был код, как показано ниже

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);
      });
    }

И получите данные, как показано ниже

После погружения фильтра в ванну с теплой водой в течение по крайней мере пяти минут поместите его внижней части верхнего компонента сифона, или бункера, и зацепите нижнюю часть стеклянной трубки бункера., заполните нижний компонент сифона., вставьте бункер, фильтр и все.

Я хочу разделитьабзац после точка и запятая разделитель в массив, чтобы я мог зациклить все данные.Как я могу это сделать?Спасибо.

Ответы [ 2 ]

2 голосов
/ 19 марта 2019

попробуйте str.split(/[,.]+/); разделить абзац после точки и разделителя запятыми в массив

let str ="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.";

let splittedArray = str.split(".,");

console.log(splittedArray);
1 голос
/ 19 марта 2019

Я полагаю, вы хотите разделить строку на точка , за которой следует запятая :

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);

ИЛИ: Использование RegEx

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);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...