Skip to content

Instantly share code, notes, and snippets.

@macchiitaka
Last active May 3, 2023 13:22
Show Gist options
  • Save macchiitaka/bff08b7cedf133d60f559763108fc3cf to your computer and use it in GitHub Desktop.
Save macchiitaka/bff08b7cedf133d60f559763108fc3cf to your computer and use it in GitHub Desktop.
[demo] string to array
const foo = "foo";
// use Array.from
console.log("Array.from", Array.from(foo)); // [ 'f', 'o', 'o' ]
// use ES6 Array spread and Array.of function
console.log(Array.of(...foo)); // [ 'f', 'o', 'o' ]
// use ES6 Array spread and array literal
console.log([...foo]); // [ 'f', 'o', 'o' ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment