Wednesday 27 January 2021

java script built-in function

 JAVASCRIPT STRING FUNCTION

<script>


s1="avadhtutor";        

s2="Javascript";

document.write(s1);

//convert your string as bold or strong using .bold() function

document.write(s1.bold()+ "<br>");

                //convert your string as italics using .italics() function

document.writeln("<br>italics = " + s1.italics());

                //convert your string as capital letter, converts a string to uppercase letters

document.writeln("<br>This is Upper Case = " + s1.toUpperCase());

                //convert your string as Small letter, converts a string to LowerCase letters

document.writeln("<br>"+s1.toLowerCase());

                //returns the character at the specified index in a string

document.writeln("<br>charAt = " + s1.charAt(4)); 

                //merge a string using concat() function

document.writeln("<br>concat = "+ s1.concat(s2));

                //returns the position of the first occurrence of a specified value in a string

document.writeln("<br>index of = " + s1.indexOf('i'));

document.writeln("<br>index of = " + s1.indexOf('a'));

                //returns the position of the Last occurrence of a specified value in a string

document.writeln("<br>last index of = " + s1.lastIndexOf('i'));

                //extracts parts of a string, beginning at the character at the specified position, and returns                     //the specified number of index

document.writeln("<br>substr = " + s2.substr(2,4));

                //first is index and last is char position

        document.writeln("<br>substring  = " + s1.substring(3,4)); 

                //method searches a string for a specified value, and returns the position of the match. The                     //search value can be string or a index

document.writeln("<br>search = " + s2.search("v")); //character wise search index

                //returns a new string where the specified values are replaced.

document.writeln("<br>replace = " + s2.replace("v","j"));

</script>

___________________________________________________

JAVA SCRIPT MATH FUNCTION

<script >

                //abs(): return positive value

document.writeln("<br>abs = " + Math.abs(-2.10));

                //returns the value of x to the power of y (xy)

document.writeln("<br>Pow = " + Math.pow(3,3));

                //create a proper random function to use for all random integer purposes

document.writeln("<br>Random = " + Math.random());

                // rounds a number to the nearest integer

document.writeln("<br>Round = " + Math.round(124.900));

                //method rounds a number UPWARDS to the nearest integer

document.writeln("<br>Ceil = " + Math.ceil(2.99));

document.writeln("<br>Ceil = " + Math.ceil(-12.999));

                //method rounds a number DOWNWARDS to the nearest integer

document.writeln("<br>Floor = " + Math.floor(11.5));

document.writeln("<br>Floor = " + Math.floor(-11.999));

                //returns the number with the highest value

document.writeln("<br>Max = " + Math.max(15,20,10,50,5,120,1));

document.writeln("<br>Max = " + Math.max(-15,-20));

                //returns the number with the lowest value

document.writeln("<br>Min = " + Math.min(15,20,10,50,3));

document.writeln("<br>Min = " + Math.min(-15,-20));

                //returns the square root of a number

document.write("<br>square root" +Math.sqrt(144));

document.write("<br>Square root"+ Math.sqrt(81));

document.write("<br>Square root"+ Math.sqrt(625));

</script>


_________________________________________

DATE & TIME FUNCTION IN JAVASCRIPT

<script>

var t = new Date();

//get full system time

document.write("Get Full Time:"+ t.getTime() + "<br />");

//get current hours of system

document.write("Get Houurs" +t.getHours()+ "<br />");

//get current  Minutes of system

document.write("Get Minutes" + t.getMinutes() + "<br />");

//Get Current System Seconds 

document.write("Get Seconds " + t.getSeconds() + "<br />");

//Get Current MiliSeconds

document.write("Get MilliSeconds" +t.getMilliseconds() + "<br>");

//return integer day values

document.write("Get Day " + t.getDay() + "<br />");

//return integer month values

document.write("Get Month " + t.getMonth() + "<br />");

//get four digit full year

document.write("Get Year " + t.getFullYear() + "<br />");

</script>

___________________________________________

JAVASCRIPT ARRAY FUNCTION

<script >

//join(): join or merge  or conacat two or more array using join() function

var arr = new Array();

arr[0] = "All";

arr[1] = "Programming";

arr[2] = "Avadh ";

arr[3] = "Tutor";

document.write(arr +"<br> ");

document.write(arr[0]+"<br>");

document.write(arr.join() + "<br />");

document.write("Name:"+arr.join("<br>Name:"));

</script>

___________

<script type="text/javascript">

//delete array element runtime using pop() array function, delete last element using POP()

var arr = new Array();

arr[0] = "Learn";

arr[1] = "All";

arr[2] = "Programming";

arr[3] = "With";

arr[4] = "youtube.com/avadhtutor";

document.write("<br><br>"+arr + "<br />");

document.write(arr.pop() + "<br />");

document.write(arr+"<br>");

document.write(arr.pop() + "<br />");

document.write(arr+"<br>");

document.write(arr.pop() + "<br />");

document.write(arr+"<br>");

</script>

__________________________

<script type="text/javascript">

//push() : is used to insert or new  elements inside a array using push() function

var arr = new Array(3);

arr[0] = "Scripting";

arr[1] = "Languages";

arr[2] = "youtube.com/avadhtutor/playlists";

document.write("<br><br><br>" +arr + "<br />"); 

document.write(arr.push("jay") + "<br />");

document.write(arr+"<br>");

</script>



Learn all 
Programming and Scripting 
Languages with 

youtube.com/avadhtutor/playlists


 

No comments:

Post a Comment