0% found this document useful (0 votes)
12 views7 pages

Pra 3

The document outlines a series of JavaScript programs demonstrating various array operations, including declaring arrays using literals and constructors, as well as using methods like push, pop, shift, unshift, splice, and slice. Each section includes the aim, code, and expected output for the respective program. The examples are structured in HTML format with embedded JavaScript.

Uploaded by

Sumedh Raut
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)
12 views7 pages

Pra 3

The document outlines a series of JavaScript programs demonstrating various array operations, including declaring arrays using literals and constructors, as well as using methods like push, pop, shift, unshift, splice, and slice. Each section includes the aim, code, and expected output for the respective program. The examples are structured in HTML format with embedded JavaScript.

Uploaded by

Sumedh Raut
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/ 7

NAME:- SUMEDH SANJAY RAUT

CLASS:- CO5I(A)

ROLL NO:-532

SUBJECT:- CSS(22517)

PRACTICAL NO:- 3
Aim: Write a JavaScript program to declare an array using Array Literal.

Code:-
<!DOCTYPE html>

<html>

<head>

<title>Sumedh Raut</title>

</head>

<body>

<h1>Array Literal</h1>

<script>

var name = ["Sumedh", "Ashok", "Saurabh", "Abhay"];

document.write(name);

</script>

</body>

</html>

Output:-
Aim: Write a JavaScript program to declare an array using Array Constructor

Code:-
<!DOCTYPE html>

<html>

<head>

<title>Sumedh Raut</title>

</head>

<body>

<h1>Using Array Constructor</h1>

<script>

const name = new Array(4);

name[0] = "Sumedh";

name[1] = "Raut";

name[2] = "CO5I";

name[3] = "32";

name[4] = "GT&MC";

document.write(name);

</script>

</body>

</html>
Output:-

Aim: Write a JavaScript program to print array element using For Loop

Code:-
<!DOCTYPE html>

<html>

<head>

<title>Sumedh Raut</title>

</head>

<body>

<script>

var names = ["Sumedh", "Ashok", "Saurabh", "Abhay"];

for (let i = 0; i < names.length; i++) {

document.write(names[i] + "<br>");

var num = [32, 36, 18, 10];

for (let i = 0; i < num.length; i++) {

document.write(num[i] + "<br>");

</script>

</body>
</html>

Output:-

Aim: Write a JavaScript program to perform Push() and Pop() methods of


Array.

Code:-
<!DOCTYPE html>

<html>

<head>

<title>Sumedh Raut</title>

</head>

<body>

<script>

var sports = ["Basketball", "Boxing", "Cricket", "Archery"];

document.write("Before PUSH array elements : " + sports);

sports.push("Bowling", "Hockey");

document.write("<br><br>After PUSH array elements : " + sports);

document.write("<br><br>Before POP array elements : " + sports);

sports.pop();
document.write("<br><br>After POP array elements : " + sports);

</script>

</body>

</html>

Output:-

Aim: Write a JavaScript program to perform Shift() and Unshift() methods of


Array.

Code:-
<!DOCTYPE html>

<html>

<head>

<title>Sumedh Raut</title>

</head>

<body>

<script>

var sports = ["Basketball", "Boxing", "Cricket", "Archery"];

document.write("Before Unshift array elements : " + sports);

sports.unshift("Hockey");

document.write("<br><br>After Unshift array elements : " + sports);

document.write("<br><br>Before Shift array elements : " + sports);


sports.shift();

document.write("<br><br>After shift array elements : " + sports);

</script>

</body>

</html>

Output:-

Aim: Write a JavaScript program to perform Splice and slice methods of Array.

Code:-
<!DOCTYPE html>

<html>

<head>

<title>Sumedh Raut</title>

</head>

<body>

<script>

var sports = ["Basketball", "Boxing", "Cricket", "Archery"];

document.write("Before Splice array elements : " + sports);

sports.splice(2, 0, "Shooting", "Tennis");


document.write("<br><br>After Splice array elements : " + sports);

document.write("<br><br>Before Slice array elements : " + sports);

var Sl = sports.slice(1, 4);

document.write("<br><br>After Slice array elements : " + Sl);

</script>

</body>

</html>

Output:-

You might also like