Languages
[Edit]
EN

JavaScript - convert string to character array

4 points
Created by:
AnnLen
1789

1. Using String split() method

// ONLINE-RUNNER:browser;

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

2. Using Array.from() method

// ONLINE-RUNNER:browser;

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

3. Using Object.assign()

// ONLINE-RUNNER:browser;

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

 

Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.