0

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

Jose A.
  • 131
  • 8

1 Answers1

0

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);
Lee Taylor
  • 7,155
  • 14
  • 29
  • 44
Aman
  • 39
  • 2