The Code is as follows:
Copy codeThe Code is as follows:
Function ObjRegExp (){
Var newStr = "Drive someone up a wall ";
NewStr = newStr. replace (new RegExp (/\ s/ig ),"");
Var objJson = {};
For (var I = 0; I <newStr. length; I ++ ){
Var objChar = newStr. charAt (I );
If (objJson [objChar]) {
ObjJson [objChar] = parseInt (objJson [objChar]) + 1;
} Else {
ObjJson [objChar] = 1;
}
}
Var oDiv = document. getElementById ("objDiv ");
ODiv. appendChild (document. createTextNode ("Drive someone up a wall! "));
ODiv. appendChild (document. createElement ("<br/> "));
For (var key in objJson ){
ODiv. appendChild (document. createTextNode (key + ":" + objJson [key]);
ODiv. appendChild (document. createElement ("<br/> "));
}
}
The Html is as follows:
Copy codeThe Code is as follows:
<Body>
<Div id = "objDiv" style = "margin-top: 100px; margin-left: 300px;"> </div>
<Input type = "text" id = "txtEmail"/>
<Input id = "btnSubmit" type = "button" value = "Submit" onclick = "ObjRegExp ();"/>
</Body>