Title says it all.
I have an array of objects shown in the code below. Each object has two values, a type and a weakness. I want a user to be able to put a type into the input field, and then when submitted, check that input value against all of the objects 0 index values. Upon match, I want to return the matching objects 1 index value. I guess I am just too new and missing the easy setup. Can anyone help? I am new to programming (4 months, self taught), and trying to figure this out, so be gentle. :)
const form = document.querySelector("#main");
const button = document.querySelector("#submit");
const types = [
{
type: "normal",
weakness: "fighting",
}
];
let results = [];
form.addEventListener("submit", (e) => {
e.preventDefault();
let result = document.getElementById("type-input").value.toLowerCase();
function checkType() {
if (result.match(types.indexOf[0])) {
console.log('Yay!');
};
};
checkType();
form.reset();
});