Display String elements in reverse order:
<html> <body> <script> var name = “amar” ; for(var i=name.length-1 ; i>=0 ; i–){ document.write(name.charAt(i) + “<br/>”); } </script> </body> </html> |
Display only digits in the given string:
<html> <body> <script> var name = “amar@123” ; for(var i=0 ; i<name.length ; i++){ var ch = name.charAt(i); if(ch>=’0′ && ch<=’9′){ document.write(name.charAt(i) + “<br/>”); } } </script> </body> </html> |
Display the count of Upper-case characters, lower case characters, digits and symbols:
<html> <body> <script> var name = “Amar@123” ; var c1=0, c2=0, c3=0, c4=0; for(var i=0 ; i<name.length ; i++){ var ch = name.charAt(i); if(ch>=’A’ && ch<=’Z’) c1++; else if(ch>=’a’ && ch<=’z’) c2++; else if(ch>=’0′ && ch<=’9′) c3++; else c4++; } document.write(“Upper case characters : ” + c1 + “<br/>”); document.write(“Lower case characters : ” + c2 + “<br/>”); document.write(“Digits case characters : ” + c3 + “<br/>”); document.write(“Symbols case characters : ” + c4 + “<br/>”); </script> </body> </html> |
Display Strings in the given array:
<html> <body> <script> var arr = [“HTML”, “CSS” , “JavaScript”, “Angular” , “React” , “VueJS”]; document.write(“Array items are : <br/>”); for(var i=0 ; i<arr.length ; i++){ document.write(arr[i] + “<br/>”); } </script> </body> </html> |
Display word count in the given sentence(String):
<html> <body> <script> var line = “This is online web technologies session” ; var arr = line.split(” “); document.write(“Words count : ” + arr.length); </script> </body> </html> |
Display words in the given string:
<!doctype html> <html> <body> <script> var line = “This is online web technologies session” ; var arr = line.split(” “); for(var i=0 ; i<arr.length ; i++) { document.write(arr[i] + ” <br/>”); } </script> </body> </html> |