add,remove,slice items from an array in javascript

<html>
<head>
<title>add,remove,slice items from an array in javascript</title>
</head>
<body style="background:lightgray">
<p>Click the button to test:</p>
<button onclick="push(8)">add</button>
<button onclick="pop()">remove</button></br>
<button onclick="slice(2,3)">extract the second and the third elements from the array</button></br>
<button onclick="slice(2,4)">extract the second and the third and the fourth elements from the array</button>
</br>
<textarea style="width: 400px;height: 200px;"id="demo"></textarea>
<script>
var arr=[1,2,3,4];
function push(item) {
 arr.push(item);
 document.getElementById("demo").innerHTML =arr;
}
function pop() {
 arr.pop();
 document.getElementById("demo").innerHTML =arr;
}
function slice(a,b) {
 var citrus = arr.slice(a-1,b);
    document.getElementById("demo").innerHTML = citrus;
}
 document.getElementById("demo").innerHTML =arr;
</script>
</body>
</html>

Comments

Popular posts from this blog

How to write data into a excel file using vbscript

Format date as yyyy-mm-dd using vbscript