Monday 3 June 2013

Java Script References(properties and methods)

Here are some properties and methods. 

JS Array
·        Length
·        Prototype
Array methods
  •        Concat()  --    concatenate more than two array information

Var x=[“shankar”,”parsanamoni”];
Var y=[“vikas”,”bodla”];
Var z=[”sai”,”srinivas”];
Var name=x.concat(y,z);
  •       indexOf() --    Searches the array for the specified item, and returns its position

var fts=new array[“shankar”,”srinivas”,”dinesh”];
var a=fts.indexOf(“dinesh”);

·         join()       --     this method is used to join all all array values.
            Var x=[“shankar”,”vikas”,”Mahesh”];
            Var result.innerHTML=x. Join ();

·         pop()      --     remove the last element of an array.
            Var y=[“shankar”,”parsanamoni”,”mudiraj”];
Var x.innerHTML=y.pop();

·         Push ()    --     adds new items to the end of an array, and returns the new length.
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi")

·         Reverse() --    Reverse the order of an array
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits. Reverse();

·         Shift()       --    Removes the first element of an array and returns it.
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.shift()

output: Orange,Apple,Mango.
·         Sort()     --   sort the items of an array
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.sort();

·         toString()--   converts an array to string and returns it.
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.toString();

·         Unshift ()   --   adds new items to the beginning of an array, and returns the new length.
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.unshift("Lemon","Pineapple");
Output : Lemon,Pineapple,Banana,Orange,Apple,Mango

·         valueOf ()   --   Returns the primitive value of an array.

JS Boolean
The Boolean object is used to convert a non-Boolean value to a Boolean value (true or false).

·         toString()   --  Converts a Boolean value to a string, and returns the result
var bool = new Boolean(1);
var myvar = bool.toString();
result is :true

·         valueOf()   --   Returns the primitive of value of Boolean object
var bool = new Boolean(0);
var myvar = bool.valueOf();
result is : false

JS Date

                             The date object is used to work with date and time
                             Date object is created with new date()
                             There are four ways to instantiate date.
1.    var d=new date();
2.    var d=new date(milliseconds);
3.    var d=new date(date String);

getDate()           --   Returns the day of the month
                             var d=new Date();
                             var n=d.getDate();
js Math
                                                The Math object allows you to perform mathematical tasks
Js Number
The Number object is an object wrapper for primitive numeric values.Number objects are created with new Number ().

Js String                     the String object is used to manipulate a stored piece of text. String objects are created with new String ().

Length                  --    specifies the length of the string
                                    Var txt=”Hello World !”;
                                    Document.write(txt.length);

charAt()                 --    returns the character at the specified index
                                    var str=”Hello World”;
                                    var n=str.charAt(3);
                                    o/p : l

charCodeAt()        --     returns the character Unicode at the specified index.
                                    Var str=”Hello World”;
                                    Var n=str.charCodeAt(0);
                                    o/p : 72

concat()                --    concat the two strings and return concatenated string value
                                   var x=”shankar”;
                                   var y=”parsanamoni”;
                                   var z=x.concat(y);
                                   o/p : shankar parsanamoni

replace()               --   replace the value
                                  var x=”visit Microsoft”;
                                  var n=x.replace(“Microsoft”,”himansuit”);

slice()                    --  Extract part of a string and returns new result
                                  var n=”Hello Shankar”;
                                  var m=n.slice(0,3);
                                  o/p : Hel

split()                    --  Splits a string into an array of substrings
                                  string.split(separator,limit);
                                  var x=”Hello how are you?”;
                                  x.split(“ “);

                                  use the limit parameter

          var str="How are you doing today?";
        var n=str.split(" ",3);
        o/p : How are you
      
          use letter as a separator
     
        var str=”How are you doing todat?”;
        str.split(“o”);
        o/p : H,w are y,u d,ing t,dat?

Substr()           --  string.substr(start, length)
                           Var x=”Hello World”;
                           Var y=x.substr(1,4)
                           o/p : ello

substring()       --   Extracts the characters from a string, between two specified indices
                                  string.subString(from,to)
                                  var x=”Hello shankar how are you”;
                                  var y=x.subString(0,3)
                                  0/p : Hel

toLowerCase()    --    var x=”Hello Shankar”;
                                  var y=x.toLowerCase(x);

toUpperCase()    --    var x=”Hello World”;
                                  var y=x.toUpperCase(x);

                                  String HTML wrapper methods

Big()                    --   The big() method is used to display a string in a big font.
                                 String.big();
         var str = "Hello world!";
       document.write(str.big());

blink()             --  The blink() method is used to display a blinking string.
                                 Var str=”Hello Shankar”;

                                 Document.write(str.blink());

No comments: