The method to change a string that has commas separating its values into an array is to use the split()
method in JavaScript.
Here's an example:
let str = "apple,banana,orange";
let arr = str.split(",");
console.log(arr); // Output: ["apple", "banana", "orange"]
In this example, the split()
method is used on the string "apple,banana,orange"
with the separator ,
. This splits the string into an array of 3 values, which are "apple"
, "banana"
, and "orange"
. The resulting array is stored in the variable arr
.
Asked: 2022-04-14 11:00:00 +0000
Seen: 8 times
Last updated: May 05 '22