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

Lukashev
  • 13
  • 2

2 Answers2

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('/'))
Get Off My Lawn
  • 34,175
  • 38
  • 176
  • 338
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);
Mamun
  • 66,969
  • 9
  • 47
  • 59