91-9990449935 0120-4256464 |
JavaScript ArrayJavaScript array is an object that represents a collection of similar type of elements. There are 3 ways to construct array in JavaScript
1) JavaScript array literalThe syntax of creating array using array literal is given below: As you can see, values are contained inside [ ] and separated by , (comma). Let’s see the simple example of creating and using array in JavaScript. Test it NowThe .length property returns the length of an array. Output of the above example2) JavaScript Array directly (new keyword)The syntax of creating array directly is given below: Here, new keyword is used to create instance of array. Let’s see the example of creating array directly. Test it NowOutput of the above example3) JavaScript array constructor (new keyword)Here, you need to create instance of array by passing arguments in constructor so that we don't have to provide value explicitely. The example of creating object by array constructor is given below. Test it NowOutput of the above example
Next TopicJavaScript String
|