TypeScript code is as follows:
namespacesLab.ts:
var ArrayUtilities;
(function (ArrayUtilities) {
function reverseArray(array) {
return array.slice(0).reverse();
}
ArrayUtilities.reverseArray = reverseArray;
function lastItemOfArray(array) {
return array.slice(0).pop();
}
ArrayUtilities.lastItemOfArray = lastItemOfArray;
function firstItemOfArray(array) {
return array.slice(0).shift();
}
ArrayUtilities.firstItemOfArray = firstItemOfArray;
function concatenateArray(array1, array2) {
return array1.concat(array2);
}
ArrayUtilities.concatenateArray = concatenateArray;
})(ArrayUtilities || (ArrayUtilities = {}));
HTML code is as follows:
index.html:
<script src="namespacesLab.js"></script>
<html>
<body>
<script>
array1 = [1, 2, 3, 4, 5];
array2 = [6, 7, 8, 9, 10];
function callArrayUtil(util, array, array2 = null) {
document.getElementById("output").innerHTML = ArrayUtilities[util](
array,
array2
).toString();
}
document.getElementById("output").innerHTML = array1.toString();
</script>
<div id="output " style="width:100%;"></div>
<button onclick="callArrayUtil('reverseArray', array1)">
Reverse Array
</button>
<button onclick="callArrayUtil('lastItemOfArray', array1)">
Last Item of Array
</button>
<button onclick="callArrayUtil('firstItemOfArray', array1)">
First Item of Array
</button>
<button onclick="callArrayUtil('concatenateArray', array1, array2)">
Concatenate Array
</button>
</body>
</html>
When I click the index.html, a webpage showing four buttons appears. However, there is no array displayed.
expected result: four buttons and an array shown on the webpage
actual result: the array did not show on the webpage