1

How to split in javascript this string

s = "Shares Mil,"6,143","6,225","6,315"

in this array:

["6,143", "6,225", "6,315"]

s.split(',') doesn't work because gives:

["6", "143", "6", "225", "6", "315"]
4
  • Guessing that you might need to use Regex. Commented Feb 7, 2016 at 18:46
  • Comes from the console.... Fixed. Commented Feb 7, 2016 at 18:59
  • That's not a valid javascript string. What is the real value of s? Perhaps you have some \" in there? Commented Feb 7, 2016 at 19:29
  • Please use the search before you ask a new question. Commented Feb 7, 2016 at 19:31

1 Answer 1

0

There is a way to do it by Regex:

var rx = /("[^"]*")(?:[,$])/g
var a = s.match(rx)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.