Wednesday, July 17, 2024

Javascript String extend for new function.

Javascript String extend for new function.
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' ]

No comments :

Post a Comment

AJAX, asp, Asp.net, asp.net and sql server security, Asp.net IntemIndex, C#, Css, DataBinder.Eval, DataKeyNames, Datalist, Datapager, DataSet, DataTable, DropDownList, FindControl, gridview, JavaScript, jquery, Listview, Paging, Regex, RegularExpression, Repeater, Server side validation, Sql Server, timer, timercallback, Validation, XML, xmlnode, XPath