having a string like these
1-2-3
1-2
Using javascript How can I cut them so I can get the numbers separately like this
1
2
3
having a string like these
1-2-3
1-2
Using javascript How can I cut them so I can get the numbers separately like this
1
2
3
The .split() method returns an array of strings separated by a specified character.
const str = '1-2-3';
const newStr = str.split('-');
console.log(newStr);