-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexp6.html
More file actions
37 lines (28 loc) · 1.13 KB
/
exp6.html
File metadata and controls
37 lines (28 loc) · 1.13 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
34
35
36
37
<!DOCTYPE html>
<html>
<head>
<title>Merge Two Arrays</title>
</head>
<body>
<h3>Enter first array (numbers separated by commas):</h3>
<input id="array1" type="text" placeholder="e.g. 1,2">
<h3>Enter second array (numbers separated by commas):</h3>
<input id="array2" type="text" placeholder="e.g. 3,4">
<button onclick="merge()">Merge Arrays</button>
<p id="result"></p>
<script>
function merge() {
// Get and clean inputs
const arr1Input = document.getElementById('array1').value;
const arr2Input = document.getElementById('array2').value;
// Convert input strings to arrays, handle empty strings gracefully
const arr1 = arr1Input ? arr1Input.split(',').map(s => Number(s.trim())).filter(n => !isNaN(n)) : [];
const arr2 = arr2Input ? arr2Input.split(',').map(s => Number(s.trim())).filter(n => !isNaN(n)) : [];
// Merge using spread operator
const merged = [...arr1, ...arr2];
// Display result
document.getElementById('result').innerText = 'Merged Array: [' + merged.join(', ') + ']';
}
</script>
</body>
</html>