Expert Developer JavaScript Question:
Download Job Interview Questions and Answers PDF
How to create an array in JavaScript?
Answer:
► We can create an array in JavaScript as following ways :
► For example :
<script>
var fruits = new Array[];
fruits[0] = "Apple";
fruits[1] = "Orange";
fruits[2] = "Banana";
alert(fruits[1]);
</script>
► It will give output : Orange
► Another easier way to create an array is as follow :
<script>
var fruits = ["Apple","Orange","Banana"];
alert(fruits[0]);
</script>
► This will give output : Apple
► For example :
<script>
var fruits = new Array[];
fruits[0] = "Apple";
fruits[1] = "Orange";
fruits[2] = "Banana";
alert(fruits[1]);
</script>
► It will give output : Orange
► Another easier way to create an array is as follow :
<script>
var fruits = ["Apple","Orange","Banana"];
alert(fruits[0]);
</script>
► This will give output : Apple
Download Expert JavaScript Developer Interview Questions And Answers
PDF
Previous Question | Next Question |
What are the different functional component in JavaScript? | Explain JavaScript closures by example? |