Javascript String extend for new function.
First Approch:
Second Approch:
First Approch:
String.prototype.toArray=function(){ let arr=[]; for(let ch of this){ arr.push(ch); } return arr; } let name="suresh"; console.log(name.toArray()); //output [ 's', 'u', 'r', 'e', 's', 'h' ]
Second Approch:
String.prototype.toArray=function(){ return this.split(''); } let name="suresh"; console.log(name.toArray()); //output [ 's', 'u', 'r', 'e', 's', 'h' ]