Page 279 - Web Applications (803) Class 12
P. 279
11. Write JavaScript code to do the following:
a. Create an array of 5 fruits.
b. Add the fruit “Dragonfruit” to the array.
c. Display the entire array
Ans. <html>
<head>
<title>Working with Arrays</title>
</head>
<body text=”green”>
<h1>Working with Arrays</h1>
<script>
var fruits = [“Apple”,”Banana”,”Orange”,”Grapes”,”Pear”];
fruits[5]=”Dragonfruit”;
document.write(“The contents of the array are....”+”<br>”);
for (var i = 0; i < fruits.length; i++) {
document.write(fruits[i]+”<br>”);
}
</script>
</body>
</html>
Output:
Practical Work 277

