Computer Science, asked by dink43, 1 year ago

which of the following is the correct way for writing Java script array

Answers

Answered by Arslankincsem
13

The correct way to write a JavaScript array var txt = new Array("arr ","kim","jim").


JavaScript arrays are used to store multiple values in a single variable.


Using an array literal is the easiest way to create a JavaScript Array.


Syntax: var array_name = [item1, item2, ...];


Example: var cars = ["Saab", "Volvo", "BMW"];

Answered by Anonymous
2

Hi,

There are two ways of making array in javascript

1. Using Array() function

or

2. Using array literal []

Let's see how to make an array using Array() function

syntax:

var nameOfArray = Array(value1, value2, value3, ...);

example:

var myFriends = Array('Ajay', 'Pankaj', 'Sandeep', 'Mukesh');

and now let's array literal syntax and example

syntax:

var nameOfArray = [value1, value2, value3, ...];

example:

var myFriends = ['Ajay', 'Pankaj', 'Sandeep', 'Mukesh'];


Similar questions