Recipe 4Extracting Lists from Text with slice()

Task

Suppose you run an online shop selling thousands of different clothes. You’re tasked with making the products searchable by color. The problem is the available colors for each product are listed as a sentence in the product description. You need a way to find and extract those colors programmatically to build a searchable database.

So if you have a product description like this:

 Feel confident in even the most unforeseen weather conditions with these
 waterproof trail-running shoes helping you stay dry. Available in four new
 colors: Velvet Brown, Black, Golden Moss, Medium Blue.

You want to extract the colors and store them in an array like this:

 [​"Velvet Brown"​, ​"Black"​, ​"Golden Moss" ...

Get Text Processing with JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.