Skip to content

How do I split a sentence or words that are separated by a comma

This example demonstrates splitting a sentence or words separated by a comma.

In the solution shown below, the list of colors "Blue,Green,Red,Yellow" are splitted into an array using "split("<separator>")".

Solution:

# Command Target Value
Splitting the words separated by a comma
1 storeEval
function f(){ var colors = "Blue,Green,Red,Yellow"; var color=colors.split(","); return color[0]; }f();first_color

Tips, Tricks, Gotchas & Best Practices:

  • As a best practice, it is always advisable to define the variable names without any spaces and if you want to differentiate the words, use underscores.


Feedback and Knowledge Base