Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

get array from string javascript

const string = 'hi there';

const usingSplit = string.split('');
const usingSpread = [...string];
const usingArrayFrom = Array.from(string);
const usingObjectAssign = Object.assign([], string);

// Result
// [ 'h', 'i', ' ', 't', 'h', 'e', 'r', 'e' ]
// From https://www.samanthaming.com/tidbits/83-4-ways-to-convert-string-to-character-array/
Source by learn.coderslang.com #
 
PREVIOUS NEXT
Tagged: #array #string #javascript
ADD COMMENT
Topic
Name
5+8 =