Convert String To Character Array – Javascript

In this post we lean three method to convert string to character array in javascript.

1. String split() method

The split() method divides a String into an ordered list of substrings, puts these substrings into an array, and returns the array. 

var text = 'ABCD';
var array = text.split('');
console.log(array);

Result

A,B,C,D

2. Array.from() method

The Array.from() static method creates a new, shallow-copied Array instance from an array-like or iterable object.

var text = 'ABCD';
var array = Array.from(text);
console.log(array);

Result

A,B,C,D

3. Object.assign() method

The Object.assign() method copies all enumerable own properties from one or more source objects to a target object. It returns the modified target object.

var text = 'ABCD';
var array = Object.assign([], text);
console.log(array);

Result

A,B,C,D