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' ]
0 Comments:
Post a Comment