home

Javascript Array

Learn arrays concepts with simple examples like how to create new array and how store objects(multiple data) as a single array and calling to use in the function.

Array Definition:-Array will work like a container truck, array can store multiple object in a single variable at time.

Array starts with 0 index and array is special variable which can store more then one, so simply which can store more than one value at a time that is called Array.

See the below code example code of array

Creating array with new array variable like "mycities" with different objects like cities names (New York, Los Angeles, Mumbai, Beijing). here multiple values holding a single variable.

*Colour Indicates the methods
<script>
  var i;
  var mycities = new Array();
  mycities[0] = "New York";
  mycities[1] = "Los Angeles ";
  mycities[2] = "Mumbai";
mycities[3] = "Beijing";
for (i=0;i<mycities.length;i++)
  {
  document.write(mycities[i] + "<br>");
  }
</script>

Array Out Put

Okay fine here we have only 5 Cities if we have 500 cities? How do you do?, So array can store more values under a single variable or single name in this case array is the method.

JavaScritp Array types to write

There are three type are there-1)Regular, 2)Condensed, 3)Literal

Regular-First Example which we covred inabove example called is Regular type.
//Condensed
var mycities=new Array(
"New York",
"Los Angeles",
"Mumbai",
"Beijing");
//Literal
var mycities=[
"New York",
"Los Angeles",
"Mumbai",
"Beijing"];