0

I get one string by query like '5e6,5e4,123'.
And I want to make an array containing this query as below in JS.

['5e6', '5e4', '123']

How can I make this? Thank you so much for reading it.

Joundill
  • 5,418
  • 11
  • 31
  • 47
Thomas Jason
  • 498
  • 1
  • 5
  • 15

5 Answers5

1

You can use .split(',')

var str = "5e6,5e4,123";
var array = str.split(',');

console.log(array);

You can read more on this here

Hisham Bawa
  • 440
  • 5
  • 14
0

Use String.split:

console.log('5e6,5e4,123'.split(","))
marco-a
  • 5,590
  • 1
  • 17
  • 43
0

You can make use of split method of string like below:

var res = str.split(',');

Joundill
  • 5,418
  • 11
  • 31
  • 47
Harmandeep Singh Kalsi
  • 3,215
  • 2
  • 13
  • 22
0
 var query = '5e6,5e4,123';
 var queries = query.split(‘,’);
tbone849
  • 797
  • 7
  • 18
-1
const output = input.split(',');
Evert
  • 83,661
  • 18
  • 106
  • 170