|
INTERVIEW QUESTIONS
WEB
JAVA SCRIPT
DETAILS
Question: How to create arrays in JavaScript?
Answer: We can declare an array like this var scripts = new Array() We can add elements to this array like this
scripts[0] = " PHP" scripts[1] = " ASP" scripts[2] = " JavaScript" scripts[3] = " HTML"
Now our array scripts have 4 elements inside it and we can print or access them by using their index number. Note that index number starts from 0. To get the third element of the array we have to use the index number 2. Here is the way to get the third element of an array. document.write(scripts[2]) We also can create an array like this var no_array = new Array(21, 22, 23, 24, 25)
|
|
|
Category |
Java Script Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.2) By 8668 users |
Added on |
9/22/2014 |
Views |
70138 |
Rate it! |
|
|
Question:
How to create arrays in JavaScript?
Answer:
We can declare an array like this var scripts = new Array() We can add elements to this array like this
scripts[0] = " PHP" scripts[1] = " ASP" scripts[2] = " JavaScript" scripts[3] = " HTML"
Now our array scripts have 4 elements inside it and we can print or access them by using their index number. Note that index number starts from 0. To get the third element of the array we have to use the index number 2. Here is the way to get the third element of an array. document.write(scripts[2]) We also can create an array like this var no_array = new Array(21, 22, 23, 24, 25) Source: CoolInterview.com
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
How do you convert numbers between different bases in JavaScript?
|
View Answer
|
|
What are JavaScript Data Types?
|
View Answer
|
|
How do you submit a form using JavaScript?
|
View Answer
|
|
What are decodeURI() and encodeURI() functions in JavaScript?
|
View Answer
|
|
What's Prototypes for JavaScript?
|
View Answer
|
|
How to create a function using function constructor?
|
View Answer
|
|
What does break and continue statements do in JavaScript?
|
View Answer
|
|
What is eval() in JavaScript?
|
View Answer
|
|
How to associate functions with objects using JavaScript?
|
View Answer
|
|
How to create an object using JavaScript?
|
View Answer
|
|
How to shift and unshift using JavaScript?
|
View Answer
|
|
How to make a array as a stack using JavaScript?
|
View Answer
|
|
How to use "join()" to create a string from an array using JavaScript?
|
View Answer
|
|
How to use strings as array indexes using JavaScript?
|
View Answer
|
|
How to delete an array entry using JavaScript?
|
View Answer
|
|
What does the delete operator do?
|
View Answer
|
|
What's the Date object using JavaScript?
|
View Answer
|
|
What's Math Constants and Functions using JavaScript?
|
View Answer
|
|
How to test for bad numbers using JavaScript?
|
View Answer
|
|
How to convert numbers to strings using JavaScript?
|
View Answer
|