Talking City

Go Back   Talking City > Coding and Programming > JavaScript programming
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Thread Tools Search this Thread Display Modes
Old 04-25-2016, 11:26 AM
Daljeet Daljeet is offline
Senior Member
Join Date: Dec 2014
Posts: 206
Daljeet is on a distinguished road
Default JavaScript

How can you create an Array in JavaScript?

Reply With Quote
Old 04-25-2016, 11:31 AM
megri's Avatar
megri megri is offline
Join Date: Mar 2004
Location: Chandigarh India
Posts: 699
megri is on a distinguished road
Send a message via MSN to megri Send a message via Yahoo to megri

You can create an array using either

an array initializer (array literal) or
the Array constructor.
The array initializer (array literal) syntax is simple: a comma-separated list of values in square brackets. Here are some examples:

var myArray1 = [1,3,5,7,9] // an array with 5 elements
var myArray2 = [5] // an array with 1 element
var myArray3 = [true,'Hi',[7]] // element types need not be the same!

The Array constructor syntax has three different forms. If you call the constructor with two or more arguments, the arguments initialize the array elements. If you only supply one argument to the Array constructor, the argument initializes the length of the new array; the new array’s elements are not initialized. Finally, if you call the constructor without arguments, the new array’s length is set to zero, and its elements are not initialized. Here are examples:

var myArray4 = new Array(1,3,5,7,9) // an array with 5 elements
var myArray5 = new Array(100) // an empty array of length 100
var myArray6 = new Array() // an empty array of length 0
Parveen K - Forum Administrator
SEO India - TalkingCity Forum Rules - SEO Forum
Please Do Not Spam Our Forum
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off

All times are GMT +5.5. The time now is 02:15 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Talking City Managed by Megrisoft