My goal is to extract and separate different numbers from an array as each number holds a unique significance. To achieve this, I am retrieving input values where the numbers are separated by spaces (" "), then attempting to split them so that each number resides in a distinct position within an array. However, every time I display my array, all the numbers end up in the [0] index. Here's the snippet of code:
input = document.getElementById('input');
button = document.getElementById('button');
button.addEventListener('click', identifyPatientZero);
function identifyPatientZero(){
var data = input.value;
slicedData = data.split(" ");
var dataArray = new Array;
dataArray.push(slicedData);
var n = dataArray[0];
var c = dataArray[1];
document.write(n);
document.write(c);
}
When 'n' is displayed on the page, it shows all the numbers together, while 'c' remains undefined. What could be causing this issue?