xxxxxxxxxx
var string = "0,1";
var array = JSON.parse("[" + string + "]");
xxxxxxxxxx
// our string
let string = 'ABCDEFG';
// splits every letter in string into an item in our array
let newArray = string.split('');
console.log(newArray); // OUTPUTS: [ "A", "B", "C", "D", "E", "F", "G" ]
xxxxxxxxxx
const str = 'Hello!';
console.log(Array.from(str)); // ["H", "e", "l", "l", "o", "!"]
xxxxxxxxxx
var myString = 'no,u';
var MyArray = myString.split(',');//splits the text up in chunks
xxxxxxxxxx
let string = "Hello World!"
let arr = string.split(' '); // returns ["Hello","World!"]
let arr = string.split(''); // returns ["H","e","l","l"," ","W","o","r","l","d","!"]
let string = "Apple, Orange, Pear, Grape"
let arr = string.split(','); // returns ["Apple","Orange","Pear","Grape"]
xxxxxxxxxx
str = 'How are you doing today?';
console.log(str.split(' '));
>> (5) ["How", "are", "you", "doing", "today?"]
xxxxxxxxxx
var a = "['a', 'b', 'c']";
a = a.replace(/'/g, '"');
a = JSON.parse(a);
xxxxxxxxxx
function stringToArray(string){
const arr = string.split(" ");// add space in between qoutes to avoid splits every letters in string
return arr
}
//splitting
const str = stringToArray('hello world!');
console.log(str); //output: [ 'hello', 'world!' ]
xxxxxxxxxx
var fruits = 'apple, orange, pear, banana, raspberry, peach';
var ar = fruits.split(', '); // split string on comma space
console.log( ar );
// [ "apple", "orange", "pear", "banana", "raspberry", "peach" ]
xxxxxxxxxx
// Designed by shola for shola
str = 'How are you doing today?';
console.log(str.split(" "));
//try console.log(str.split("")); with no space in the split function
//try console.log(str.split(",")); with a comma in the split function