CBSE 18. WEB SCRIPTING - JAVA SCRIPT (5 MARKS)

 

26. Adding a New Element to an Array (using push())

JavaScript

<!DOCTYPE html>

<html>

<head>

<title>Adding to Array</title>

</head>

<body>

 

<script>

  var fruits = ["apple", "banana"];

  fruits.push("orange");

  document.write(fruits);

</script>

 

</body>

</html>

This adds the element "orange" to the end of the fruits array.

No comments:

Post a Comment