+ 3

How to create an array?

30th Dec 2016, 11:20 AM
Vipul Aggarwal
Vipul Aggarwal - avatar
6 Respuestas
+ 5
var fruits=["red","green","blue"]; alert(fruits[0]);
30th Dec 2016, 1:08 PM
Sandeep Chatterjee
+ 4
var arr = ["hello","world"];
30th Dec 2016, 11:24 AM
Nguyễn Hoàng Long
Nguyễn Hoàng Long - avatar
+ 4
var arr = new Array("a", "b", "c");
30th Dec 2016, 1:51 PM
zakaria mouhid
zakaria mouhid - avatar
+ 1
var array = new Array("1", "2");
19th Jan 2017, 5:49 PM
Ивана Кривчевска
Ивана Кривчевска - avatar
0
You can use new Array( ) but everyone on the web recommends the literal [ ] : var a = [ ] //creates an empty array as well. The reason being 'new Array()' is ambiguous and inconsistent and especially for developers from other languages very confusing. The performance gain is so minor and not even guaranteed depending on the browser. So you are advised to initialize your arrays with [].
3rd Jan 2017, 3:14 PM
MarquisBs
MarquisBs - avatar
0
excuse me how do do the other create array with document.write(example );
3rd Sep 2021, 11:32 PM
Rishabh Sharma
Rishabh Sharma - avatar