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 Answers
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('/'))
2 Comments
Maess
Based on his example: "Color of model: White/White/White" you need an additional first split on ':'
Get Off My Lawn
I wasn't sure that
Color of model: was part of the string... I'll fixMay 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);