-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTutorial16 arrayMethod.html
More file actions
33 lines (31 loc) · 1.66 KB
/
Tutorial16 arrayMethod.html
File metadata and controls
33 lines (31 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<!doctype html>
<html>
<head>
<title>
Tutorial 1 JavaScript -- Hello World
</title>
</head>
<body>
<script type="text/javascript">
var myArray1 = ["Sunday","Monday","Tuesday"];
var myArray2 = ["Wednesday","Thrusday","Friday","Saturday","Sunday"] ;
var fullweek = myArray1.concat(myArray2);
document.write("Full week is " + fullweek+ " and type of it is: "+ typeof(fullweek) + "<br/>" );
var weektogether = fullweek.join();
document.write("Full week is " + weektogether + " and type of it is: "+ typeof(weektogether)+ "<br/>"); // by default it adds a comma(,)between elements.
var weektogethernow = fullweek.join("-");
document.write("Full week is " + weektogethernow + "<br/>"); //It will add hyphen(-) among the string.
/* Take Aways : - Some of the array method has the same name as string.
- concat: joins multiple arrays.
- join: Join all the elements of the array in the string.
- toString: returns the array as a string.
- indexof: Searchs the array for specific elements.
- lastindexof: returns the last item in the array that matches the search creteria.
- slice: returns a new array from the specified index and length.
- sort: Sorts the array alphabetically or by supplied function
- splice: Adds or deletes the specified index(es) to or from the array.
}
*/
</script>
</body>
</html>