Currently, I am utilizing an input field to gather user inputs and store them in an array.
The main objective is to verify whether the number inputted by the user already exists in the array. If it does, then the input should not be duplicated.
Below is my implementation:
if(e.keyCode === 43){
var num = document.getElementById("numbers").value;
var oks = [];
// Set value of 'num'
// Check if 'num' is present in the 'oks' array
if( oks[num]==num ){
alert("This number already exists.");
}
else{
oks[num.value]=num.value;
}
console.log(oks.value);
}
However, upon running the code above, the console log displays 'undefined'.
Please assist me in identifying the mistake in my approach.
Thank you for your support :)