Skip to content

Instantly share code, notes, and snippets.

@joelpalmer
Created July 3, 2015 21:01
Show Gist options
  • Save joelpalmer/7a8009494363a6930f32 to your computer and use it in GitHub Desktop.
Save joelpalmer/7a8009494363a6930f32 to your computer and use it in GitHub Desktop.
String.toCharArray()
/* Created by Joel Palmer on 7/3/2015.
ES6 --- FireFox 32+ only as of Created by date
Doc & Polyfill: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from
*/
//create an array from function arguments
var args = function(){
return Array.from(arguments);
};
console.log(args(31, "Joc", "Pederson"));
//create an array from a string -- toCharArray()
String.prototype.toCharArray = function(){
return Array.from(this);
};
var text = "Dodgers";
console.log(text.toCharArray()); // Array [ "D", "o", "d", "g", "e", "r", "s" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment