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

Css 3

The document contains code snippets demonstrating the use of arrays in JavaScript. It shows how to create arrays using literals and the new keyword. It also demonstrates common array methods like sort(), reverse(), push(), pop(), unshift(), shift(), and splice() to manipulate and traverse array elements. The code prints the arrays before and after applying each method to show their effects.

Uploaded by

ayush
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views

Css 3

The document contains code snippets demonstrating the use of arrays in JavaScript. It shows how to create arrays using literals and the new keyword. It also demonstrates common array methods like sort(), reverse(), push(), pop(), unshift(), shift(), and splice() to manipulate and traverse array elements. The code prints the arrays before and after applying each method to show their effects.

Uploaded by

ayush
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Name:-Ayush Maroti Wadje Roll No:-76 Class:-CO5I

CODE:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Creating Array</title>
<script type="text/javascript">
// array by literal
document.write("Array by literal" + "<br>");
var arr1 = [1,2,3,4,5,6];

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

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

}
// array by new keyword
document.write("Array by new keyword"+"<br>");
var arr2 = new Array();
arr2[0] = "hello";
arr2[1] = "hello_world";
arr2[2] = "hi";

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


document.write(arr2[i]+ "<br>");
}
</script>
</html>
CODE:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Array Method</title>
<script type="text/javascript">
var arr = [34,54,23,76,1];
document.write("before sorting:" + "<br>");
for(var i = 0 ; i < arr.length ; i++) {
document.write(arr[i]+"<br>");
}
document.write("<br><hr>");
document.write("After sorting:"+"<br>");
arr.sort();
for(var i = 0 ; i < arr.length ; i++) {
document.write(arr[i]+"<br>");
}
document.write("<br><hr>");
document.write("Reverse array:"+"<br>");
arr.reverse();
for(var i = 0 ; i < arr.length ; i++) {
document.write(arr[i]+"<br>");
}
</script>
</head>
</html>
CODE:
<html>
<head>
<meta charset="utf-8">
<title>Array Methods</title>
<h1>Use of shift,unshift,push and pop method</h1>
<script type="text/javascript">

var arr = ["python","c++","c","java"];


document.write("Original Length: " + arr.length + "<br><br>");
for(var i = 0 ; i < arr.length; i++) {
document.write(arr[i] + "<br>");
}
document.write("<hr>”)
arr.push("C#");
arr.push("ruby");
arr.pop("java");
arr.unshift("objective c");
arr.unshift("perl");
arr.shift("python");
arr.splice(5);

document.write("Current Length: " + arr.length + "<br><br>");

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


document.write(arr[i] + "<br>");
}
</script>
</head>
</html>

You might also like