0

I have the following multi-line string that has been escaped for new-lines:

var types = "a\
             b\
             c\
             d";

I'm trying to split them by new-lines:

var data = types.split('\n');

I've had no luck with this.. How do I do this?

1
  • 1
    Well, since the new lines are escaped, it doesn't contain new line characters. You could split by spaces instead, or you have to introduce another delimiter. Commented Jun 21, 2014 at 4:59

1 Answer 1

2

Try splitting with regex:

types.split(/ */)

Live demo

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

Comments

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.