-4

I have a string "Color of model: White/White/White". I want to find out, how to get all colors(White,White,White) without 'slashes' and make array from this values.Quantity of colors can change (White/Green/Yellow/Black etc)

2
  • You'll get a better answer if you tag this with which language you are interested in. Commented May 23, 2018 at 15:06
  • @maess i don't get your point. Commented May 23, 2018 at 15:07

2 Answers 2

4

You need to use split:

let colors = 'Red/White/Blue'

console.log(colors.split('/'))

If you need to include Color of model: you will need to split twice, once on the : and then on the second array parameter.

let colors = 'Color of model: Red/White/Blue/Green/Purple/Black'

console.log(colors.split(/:\s+/, 2)[1].split('/'))

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

2 Comments

Based on his example: "Color of model: White/White/White" you need an additional first split on ':'
I wasn't sure that Color of model: was part of the string... I'll fix
2

May be you can do the following by using String.prototype.split():

var str = "Color of model: White/White/White";
var color = str.split(':')[1].split('/').join(',');
console.log(color);

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.