-1

I want to create an Array from strings

That is how the string is formatted

const someString = "a,b,c,d";

And I need an Array like this

const someArray = ["a", "b", "c", "d"];
four-eyes
  • 10,740
  • 29
  • 111
  • 220

2 Answers2

1

Use String.prototype.split()

const someString = "a,b,c,d";
const someArray = someString.split(',');

MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split

Chiffie
  • 581
  • 3
  • 18
1

You can simply split the string:

const arr = "a,b,c,d".split(",")

Sam L
  • 303
  • 1
  • 9