0% found this document useful (0 votes)
39 views

Practical No 3

Practical 3 of CSS

Uploaded by

huzaifasajid73
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)
39 views

Practical No 3

Practical 3 of CSS

Uploaded by

huzaifasajid73
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/ 16

Practical No.

Aim: Develop JavaScript to implement Array functionalities.

<html>

<head>

<title> Array </title>

</head>

<body>

<script>

var a1= new Array();

document.write("Length of a1 array is :" + a1.length);

var a2= new Array(3);

document.write("<br>Length of a2 array is :" + a2.length);

var a3 = new Array(5, 4, 3, 2, 1, "testing, testing");

document.write("<br>Length of a3 array is:" + a3.length);

</script>

</body>

</html>

<html>

<head>

<title> Array </title>

</head>

<body>

<script>

var items = new Array("One", "Two", "Three");

document.write("Length of array is :" + items.length);


</script>

</body>

</html>

<html>

<head>

<title> Array </title>

</head>

<body>

<script>

var items = new Array(3);

items[0] = "One";

items[1] = "Two";

items[2] = "Three";

document.write(items[0]);

document.write("<br>"+ items[1]);

document.write("<br>"+items[2]);

</script>

</body>

</html>

<html>
<head>

<script>

var scripts=new Array();

scripts[0]="PHP";

scripts[1]= "ASP";

scripts[2] = "JavaScript";

scripts[3] = "HTML";

for (i=0;i<scripts.length;i++)

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

</script>

</head> </html>

<html>

<head>

<script>

var arr = new Array();

for (i=0; i< 5; i++){

arr[i] = i;

for (i = 0; i< 5; i++){

document.write("element = "+ arr[i] +"<br>");

</script>

</head>

</html>
<html>

<head>

<script>

var arr = new Array("one", "two", 30);

document.write("Length of array=" + arr.length +"<br>");

for (i=0; i< 3; i++)

document.write("element = "+ arr[1] +"<br>");

</script>

</head>

</html>

<html>

<head>

<title> Array </title>

</head>

<body>

<script>

var num = new Array(3); for (i = 0; 1 < 3; i++) num[i] = new Array(3);
num[0][0] = 1;

num[0][1] = 2;

num[0][2] = 3;

num[1][0] = 4;

num[1][1] = 5;

num[1][2] = 6;

num[2][0] = 7;

num[2][1] = 8;

num[2][2] = 9;

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

for (var j=0; j < num.length; j++)

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

</script>

</body>

</html>

<html>

<head>

<title> Array </title>


</head>

<body>

<script>

var items = new Array(3);

items[0] = "One";

items[1] = "Two";

items[2] = "Three";

items[3] = "Four";

items.push("Five");

items.push("Six", "Seven");

items.unshift("Zero");

items[items.length]="Eight";

items[items.length]="Nine";

for (i=0;i<items.length;i++)

document.write(items[i] + " ");

</script>

</body>

</html>

<html>

<body>

<script>

var products = new Array();

products[0] = 'Soap ';

products[1] = 'Water';

products[2] = 'Pizza';
products[3] = 'Fan';

products.sort();

for (var i = 0; i < products.length; i++)

document.write(products[i] + '<br>');

</script></body>

</html>

<html>

<head>

<title> Array </title>

</head>

<body>

<script>

var arr1 = [ "Red", "RED", "red", "Green", "Blue"];

var arr2 = [1, 20, 3, 45, 44, 0.5];

document.write("Before sorting arr1="+ arr1);

document.write("<br>After sorting arr1="+ arr1.sort());

document.write("<br>Before sorting arr2="+ arr2);

document.write("<br>After sorting arr2="+ arr2.sort(function(a,b){return a-b}));

</script>

</body>

</html>
<html>

<head>

<title> Array </title>

</head>

<body>

<script>

var arr1 = [ "Red", "RED", "red", "Green", "Blue"];

var arr2= [1, 20, 3, 45, 44, 0.5];

arr1.sort();

document.write("Descending Order : "+arr1.reverse()+"<br>");

document.write("Descending Order : "+arr2.sort(function(a,b){return b-a}));

</script>

</body>

</html>

<html>

<body>

<script>
var fruits = ["Banana", "Watermelon", "Chikoo", "Mango", "Orange", "Apple"];

fruits.sort();

document.write(fruits+"<br>");

fruits.reverse();

document.write(fruits+"<br>");

</script>

</body>

</html>

<html>

<body>

<script>

var CO_Subject = ["PHP", "CSS", "Java"];

var Math_Subject= ["Applied Math", "Elements of Maths"];

var subjects = CO_Subject.concat(Math_Subject);

document.write(subjects);

</script>

</body>

</html>

<html>

<head>

<title> Array </title>


</head>

<body>

<script>

var items = new Array(3);

items[0] = "One";

items[1] = "Two";

items [2]="Three";

var s1=items.join()

document.write(s1 + "<br>");

var s2=items.join('-')

document.write(s2 + "<br>");

var s3=items.concat()

document.write(s3 + "<br>");

var num = new Array(3);

num[0] = "Four";

num[1]="Five";

num[2] = "Six";

var s4=items.concat(num);

document.write(s4 + "<br>");

</script>

</body>

</html>

<html>

<body>

<script>
var products = new Array();

products[0] = 'Car ';

products[1] = 'Water';

products[2] = 'Soap';

products[3] = 'Pizza';

var str = products.concat();

document.write(str);

document.write('<br>');

var str = products.join(' ');

document.write(str);

</script>

</body>

</html>

<html>

<head>

<script>

var arr = new Array(1,2,3,4,5,6,7,8,9,10);

document.write("<br>After join method "+ arr.join("-"))

var newarr=arr.slice(1,3)

document.write("<br>After slice method "+ newarr)

</script>

</head>

</html>
<html>

<head>

<title> Array </title>

</head>

<body>

<script>

var items=new Array(3);

items[0] = "One";

items[1] = "Two";

items[2]="Three";

items.shift();

for (i=0;i<items.length;i++)

document.write(items[i] + " ");

</script>

</body>

</html>

<html>

<head>

<title> Array </title>

</head>
<body>

<script>

var items = new Array(3);

items[0] = "One";

items[1] = "Two";

items[2] = "Three";

items.pop();

for (i=0;i<items.length;i++)

document.write(items[i] + " ");

</script>

</body>

</html>

<html>

<body>

<script>

var fruits=["Banana","Watermelon","Chikoo","Mango","Orange","Apple"];

document.write(fruits+"<br>");

fruits.splice(2,2, "Lemon", "Kiwi");

document.write(fruits+"<br>");

fruits.splice(0,2);

document.write(fruits+"<br>");

</script>

</body>

</html>
<html>

<body>

<script>

var fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];

document.write(fruits);

var citrus = fruits.slice(2);

document.write("<br>"+citrus);

</script>

</body>

</html>

<html>

<head>

<title> Array </title>

</head>

<body>

<script>

var arr={"One": 1, "Two": 2, "Three": 3};

for (var key in arr)

var value=arr[key];
document.write(key+"=" + value + '<br>');

</script>

</body>

</html>

<html>

<head>

<title> Array </title>

</head>

<body>

<script>

var o=new Object();

o["One"] = 1;

o["Two"] = 2;

o["Three"] = 3;

for (var i in o)

document.write(i + "=" + o[i] + '<br>');

</script>

</body>

</html>
<html>

<head>

<script>

var arr = new Array();

arr.push (5, 6, 7);

arr.push (8, 9);

document.write("After join method "+arr.join(","))

arr.pop()

document.write("<br>After pop method "+arr.join(","))

arr.shift()

document.write("<br>After shift method "+arr.join(","))

arr.reverse()

document.write("<br>After reverse method "+arr.join(","))

arr.unshift(1)

document.write("<br>After unshift method "+arr.join(","))

</script>

</head>

</html>

You might also like