Arrays are simple ways to store various data, it is possible to allocate them in a single memory space various data. In Javascript, it is used from the array object and has three types of calls, as example below:

<SCRIPT LANGUAGE=”JavaScript” TYPE=”text/javascript”>
//simple call without scaling
Vet1 = new Array();

//simple call without scaling
Vet2 = new Array(2);

//simple call with values
Vet3 = new Array (“Texto 1″, “Texto 2″);

</SCRIPT>

The type of logic to be implemented is that which defines the call type to be used.

Just as in other programming languages​​, an array has a first position accessed from the zero position. So, if you want to access data from an array is important to take this item into consideration, check out:

<SCRIPT LANGUAGE=”JavaScript” TYPE=”text/javascript”>
var Vet = new Array (“Texto 1″, “Texto 2″);
document.write(“<p>”);
document.write(“First position: ” + Vet[0]);
document.write(“</br>Second position: ” + Vet[1]);
document.write(“</p>”)
</SCRIPT>

In the above example used the method call passing the values ​​of the array and then written in the following respective amounts screen informing the positions according to the description in the row.

The array object still has some important attributes, one is lenght that informs the current size of the array and can be used as a parameter to sweep all positions in the code below is an example of practical use:

<SCRIPT LANGUAGE=”JavaScript” TYPE=”text/javascript”>
var Vet = new Array (“1”, “2”, “3”);
document.write (“<p>This array has ” + Vet.length + ” numbers. These numbers are:</p>”);
document.write (“<ul>”);
for (index=0;
index < Vet .length;
index++){
document.write (“<li>” + Vet[index] + “</li>”)
}
document.write (“</ul>”);
</SCRIPT>

The use of arrays is very common, so it is important that you understand your logic utilization. Many everyday problems of a programmer can be solved with a simple array and learn to manipulate them is essential.

javascript

Test this and other code in Javascript in Scriptcase and also learn about other resources that our tool provides. Download the free version now and learn how to have more results with their web applications.

You might also like…

SCRIPTCASE: What is VS What is not

What is VS What is not What is ScriptCase? It is a fast development environment with tools that f...

Conversion Process to Scriptcase 9

How to perform the conversion process to Scriptcase 9 For this Guide to perform the conversion proc...

You might also like…

Get new posts, resources, offers and more each week.

We will use the information you provide to update you about our Newsletter and Special Offers. You can unsubscribe any time you want by clinck in a link in the footer of any email you receive from us, or by contacting us at sales@scriptcase.net. Learn more about our Privacy Police.