0

I had code like below

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

And get data like below

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.

I want to split the paragraph after dot and comma delimiter into an array so I can loop all the data. How can I do that? Thanks.

7
  • Please post your existing code so we can help you fix it. This isn't a code request service so you need to show us what you've already tried. Commented Mar 19, 2019 at 13:48
  • 1
    str.split(/[.,]+/) Commented Mar 19, 2019 at 13:49
  • 1
    String.split() ? For the record, this is a very basic method you learn in every tutorial. Commented Mar 19, 2019 at 13:49
  • w3schools.com/jsref/jsref_split.asp Commented Mar 19, 2019 at 13:49
  • 1
    Have you tried the suggestions below? One of them does exactly what you've asked for. Commented Mar 19, 2019 at 14:36

2 Answers 2

2

I believe you want to split the string by dot followed by comma:

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

OR: Using 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);

Sign up to request clarification or add additional context in comments.

Comments

2

try str.split(/[,.]+/); to split the paragraph after dot and comma delimiter into an array

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 Comment

@Archer sorry, now I got Questions. I have updated my answer. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.