Last active
May 3, 2023 13:22
-
-
Save macchiitaka/bff08b7cedf133d60f559763108fc3cf to your computer and use it in GitHub Desktop.
[demo] string to array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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