Posts

Showing posts from October, 2015

How to Loop through the Java Script Arrays

Image
How to iterate the data in an Array or the j son ? Fist Let us have one simple Array with few objects inside Example: var states=[{"name":"Andhra Pradesh"}, {"name":"Karnataka"}, {"name":"Telangana"}, {"name":"Kerala"}, {"name":"Tamil Nadu"} ] To display the Data we have to loop the Array . So let us use for loop for the same ; for (var i =0;i<states.length;i++){  document.write (states[i].name) } If you have multiple data values in the objects inside the array , you have to use the property of that object next to the array . For example let us add one more value to the existing Array . var states=[{"name":"Andhra Pradesh","capital":"Amaravathi"}, {"name":"Karnataka","capital":"Bangalore"}, {"name":"Telangana","capital":"Hyderabad"}, {...

Java Script arrays

Image
Java Script arrays are used to store multiple values  in a single variables . It may single value or collection of objects . Arrays are very important in Java Script. Let us look how can we create arrays in Java Script. we can create Java script arrays as follows . var subjects=["Telugu","Tamil","Hindi","English "] ; we can also create Java script arrays  as follows var subjects=[]; this indicates an empty array with the name of subjects; let us add some values for the arrays . Arrays value positions are started from 0 . It means in the above example the index (position )  of the Telugu is "0", and Tamil is "1", so we can add the values for the array in as follows. subjects[0]="Telugu"; subjects[1]="Tamil"; How can we retrieve or Iterate the Data from an array ? we can do it in two different methods .  The first way of doing this is by using the for loop . First wee need to find out th...

javascript objects tutorial

In JavaScript Every thing is considered as an Object except Boolean Values . Creating and Objects and accessing its properties are very important tasks in Java script. Let us discuss about an object with an Examples . Let us create an object of a "Person" <script> var person={}; This Indicates an empty object with a name of person. person.firstName="Murali"; This indicates Object having a property of First Name and its value is Murali. person.lastName="Krishna"; This indicates Object having a property of First Name and its value is Krishna. person.company="HP";This indicates Object having a property of Company  and its value is HP. </script> Now Let us look how can we access the object Properties . To access the Property of an object we have to access the object. Console.log(person.firstName); it will give the value of the person Fist name . In same way we can access all the properties.