[go: up one dir, main page]

0% found this document useful (0 votes)
17 views3 pages

Array Programs

The document provides examples of JavaScript array creation and various array methods including length, at(), pop(), and push(). Each section includes HTML code demonstrating how to use these methods and their effects on arrays. The examples show how to manipulate arrays and display results in a web page.

Uploaded by

aryantiwari10501
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views3 pages

Array Programs

The document provides examples of JavaScript array creation and various array methods including length, at(), pop(), and push(). Each section includes HTML code demonstrating how to use these methods and their effects on arrays. The examples show how to manipulate arrays and display results in a web page.

Uploaded by

aryantiwari10501
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

ARRAY CREATION

<!DOCTYPE html>

<html>

<body>

<h1>JavaScript Arrays</h1>

<p id="demo"></p>

<script>

const cars = ["Saab", "Volvo", "BMW"];

document.getElementById("demo").innerHTML = cars;

</script>

</body>

</html>

2. ARRAY METHODS

2.1 ARRAY LENGTH

2<!DOCTYPE html>

<html>

<body>

<h1>JavaScript Arrays</h1>

<h2>The length Property</h2>

<p>The length property returns the length of an array:</p>

<p id="demo"></p>

<script>

const fruits = ["Banana", "Orange", "Apple", "Mango"];

let size = fruits.length;

document.getElementById("demo").innerHTML = size;

</script>

</body>

</html>
2.2 ARRAY AT ()

<!DOCTYPE html>

<html>

<body>

<h1>JavaScript Arrays</h1>

<h2>The at() Method</h2>

<p>The at() method returns an indexed element from an array:</p>

<p id="demo"></p>

<script>

const fruits = ["Banana", "Orange", "Apple", "Mango"];

let fruit = fruits.at(2);

document.getElementById("demo").innerHTML = fruit;

</script>

</body>

</html>

2.3 ARRAY POP

<!DOCTYPE html>

<html>

<body>

<h1>JavaScript Arrays</h1>

<h2>The pop() Method</h2>

<p>The pop() method removes the last element from an array.</p>

<p id="demo1"></p>

<p id="demo2"></p>

<script>

const fruits = ["Banana", "Orange", "Apple", "Mango"];

document.getElementById("demo1").innerHTML = fruits;

fruits.pop();

document.getElementById("demo2").innerHTML = fruits;

</script>
</body>

</html>

2.4 ARRAY PUSH

<!DOCTYPE html>

<html>

<body>

<h1>JavaScript Arrays</h1>

<h2>The push() Method</h2>

<p>The push() method returns the new array length:</p>

<p id="demo1"></p>

<p id="demo2"></p>

<script>

const fruits = ["Banana", "Orange", "Apple", "Mango"];

document.getElementById("demo1").innerHTML = fruits.push("Kiwi");

document.getElementById("demo2").innerHTML = fruits;

</script>

</body>

</html>

You might also like