
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Create Arrays in JavaScript
To create an array in JavaScript, simply assign values −
var animals = ["Dog", "Cat", "Tiger"];
You can also use the new keyword to create arrays in JavaScript −
var animals = new Array("Dog", "Cat", "Tiger");
The Array parameter is a list of strings or integers. When you specify a single numeric parameter with the Array constructor, you specify the initial length of the array. The maximum length allowed for an array is 4,294,967,295.
Example
Let’s see an example to create arrays in JavaScript
<html> <head> <title>JavaScript Arrays</title> </head> <body> <script> var arr = new Array("Dog","Cat","Tiger"); var sorted = arr.sort(); document.write("Returned string is : " + sorted ); </script> </body> </html>
Advertisements