How to find current date in javascript

{0 Comments}

To find Current date using JavaScript you need to use Date inbuilt function. But the thing which you will notice is that, date you are getting by using inbuilt Date function is not in the correct format so you need to customize the JavaScript according to yourself. Which will give you date in proper format. …

Read More…

How to find a character in a string in JavaScript

{0 Comments}

There are two methods which is much more widely used in JavaScript to finding some character or part of string. This is CharAt and indexOF. CharAT CharAT is JavaScript method which will help you to get the character at particular position like at first, or eight places.  Thing to remember that here count starts from …

Read More…

How to find browser name/details in JavaScript

{0 Comments}

To get the browser detail you can use the some in built function to get the name, version, user agent and other value of the navigator. Among then the user agent property is more  reliable than appname property to get the following is the small syntax.  Javascript |  copy code |? 1var BrowserVersion = navigator.appVersion;2var Useragebt = navigator.userAgent;3var browserName = …

Read More…

How to find array length in JavaScript

{0 Comments}

To find the length of an array JavaScript inbuilt function will help you that itself named as ‘length’ this will return array length, it can also can be used to set the array length. Following is the syntax to understand how you can use this.  Javascript |  copy code |? 1<script type="text/javascript">2 3Array.length=number//set the array length4 5Array.length//return the length of array6 7</script>8

Read More…

How to find string length in JavaScript

{0 Comments}

To find the length of a string a JavaScript inbuilt function will help you that itself named as ‘length’ this will return the number of character in the string. Following is the syntax to understand how you can use this.  Javascript |  copy code |? 1<script type="text/javascript">2var someval = "it is a sample string";3 4var lengthofstring = someval.length;5 6document.write(lengthofstring);7 8

Read More…

How to find the data type of a variable in JavaScript

{0 Comments}

To check the data type of variable you can use “typeof” operator present in JavaScript. By using this operator you can conform that whether the type of variable is a string, int, or a char etc. following is the syntax to use ‘typeof’ operator  Javascript |  copy code |? 1var abc=32alert(typeof abc) This will give result as ‘number’, and following …

Read More…

How to format float/decimal in JavaScript

{0 Comments}

In JavaScript when you get result in decimal/float and it contains too much number after decimal. Like 2.34345566, and you want to format this so that you can get result like 2.34 only then you can use following trick or cheat you say.  Javascript |  copy code |? 1var result = Math.round(original*100)/100; You can change the number of Zeros to …

Read More…

How to format currency in javascript

{0 Comments}

Following is the JavaScript which will help to format currency especially for dollars.   Javascript |  copy code |? 01<SCRIPT LANGUAGE="JavaScript">02 03function formatCurrency(num) {04num = num.toString().replace(/\$|\,/g,”);05if(isNaN(num))06num = "0";07sign = (num == (num = Math.abs(num)));08num = Math.floor(num*100+0.50000000001);09cents = num%100;10num = Math.floor(num/100).toString();11if(cents<10)12cents = "0" + cents;13for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)14num = num.substring(0,num.length-(4*i+3))+’,'+15num.substring(num.length-(4*i+3));16return (((sign)?”:’-') + ‘$’ + num + ‘.’ + …

Read More…

How to format date in javascript

{0 Comments}

The JavaScript have inbuilt date class which can be used to stored and get date and time. To initialize its object we use following syntax. Var a =new date(); Above syntax a object of date class with value of current date and time.  Then you can use following functions to get each part like date, …

Read More…

How to encode html in JavaScript

{0 Comments}

To encode we use three major inbuilt encoding JavaScript function but actually it false in html tags. To smarter way to encode html string is to use replace JavaScript inbuilt function which will replace your major special character like <> and & and other tags. You can use other inbuilt function but it not work …

Read More…