Declaration of an Array
There are basically two ways to declare an array.
But generally method 1 is preferred over the method 2. Let us understand the reason for this.
Initialization of an Array
Example (for Method 1):
Example (for Method 2):
As shown in above example the house contains 5 elements i.e. (10 , 20, 30, 40, 50)while house1 contains 5 undefined elements instead of having a single element 5. Hence, while working with numbers this method is generally not preferred but it works fine with Strings and Boolean as shown in the example above home contains a single element 1BHK.
We can store Numbers, Strings and Boolean in a single array.
Accessing Array Elements
Length property of an Array
Length property of an Array returns the length of an Array. Length of an Array is always one more than the highest index of an Array.
Example below illustrates the length property of an Array:
Note : All the above examples can be tested by typing them within the script tag of HTML
Disclaimer: This does not belong to TechCodeBit, its an article taken from the below
source and credits.
We have built the accelerating growth-oriented website for budding engineers and aspiring job holders of technology companies such as Google, Facebook, and Amazon
If you would like to study our free courses you can join us at
http://www.techcodebit.com. #techcodebit #google #microsoft #facebook #interview portal #jobplacements