Introduction to Tables
The variables in JavaScript can only store one data at a time. The existence of a very great tendency to manipulate large amounts of data in one variable to make the concept of variable will not be enough to meet that need. To overcome this, JavaScript is presenting a solution that allows data structures to save a group of data in a special variable called: Table.
Table, in JavaScript is a variable that can contain many independent data, with the index based on the serial number, with this index also allows us to access data stored in certain locations.
Making Tables There are several ways to create tables in JavaScript:
var MyTable = ["data 1", "data 2", "data 3", "data 4"];
var MyTable = new Array ("data 1", "data 2", "data 3", "data 4");
On the way above the table is initialized with data values at the time it’s made. For more details, we should declare the table before we fill in with data, examples of declaration is as follows:
var MyTable = new Array ();
Accessing Data On The Table
Accessing data or element in the table can be done by specifying a table followed by parentheses containing an index of the element.
var MyTable = ["Apples", "Oranges", "Pineapple", "Watermelon", "Banana", "Melon"];
document.write ("Element 4 of the table is" + MyTable [3]);
/ / Result "Element 4 of the table is Watermelon"
Entering Data in Tables
To create associative table, simply by declaring a variable that we will enter, then write the name of the table, followed by the name of the index in brackets, and insert the data value:
MyTable [0] = "Hello";
MyTable ["John"] = 10;
MyTable ["Jack"] = 47;
Manipulating Tables
To manipulate tables, JavaScript has an object called object array, which allows us to manipulate the table, such as insert, delete or retrieve a particular element (extract) to / from a table.
0 comments:
Post a Comment