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.
  • 483
  • 2
  • 7
  • 15

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,761
  • 16
  • 33
  • 49
Aman
  • 39
  • 3