'How could I use a character to split a string into multiple?

I am using node.js and I was wondering how I could do this with a string

starting with something like "ex1:ex2:ex3"

var rl = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

rl.question('Enter a combo (1:2:3) : ', (answer) => {


});

How could I turn an input like "ex1:ex2:ex3" into individual variables that contain "ex1", "ex2", and "ex3"



Solution 1:[1]

you can use the split function

var split_string = answer.split(":");
      
console.log(split_string);

Result:

["ex1", "ex2", "ex3"]

now you can use a for loop to iterate over this array.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 aj.24