I'm trying to have my function loop through var list and match text that is pasted into a text box in HTML. For instance the only two examples right now in var list, if 'AFCOMMMDL' exists in the pasted text, I want the function to return 'Air Force Commendation Medal'. I would do this, searching the text for all of the abbreviated codes and returning the one right after and pushing it to the empty finalList[] which will eventually be printed. I'm new to Javascript and have searched this all over and can't find an answer. Thank you in advance.
function sortAwards() {
//Assign rewards variable whatever content was pasted in text box
var rewards = document.getElementById("paste").value;
//Remove spaces from pasted text
rewards = rewards.replace(/\s/g, '');
//Empty list to contain all of the matches
var finalList = [];
var list = {
'AFCOMMMDL': 'Air Force Commendation Medal',
'AFACHIEVMDL': 'Air Force Achievement Medal',
}
for (index = 0; index < list.length; index++) {
if (rewards.includes(index)) {
rewards.push[index];
}
}
//Test to show result
document.getElementById('test').innerHTML = finalList;
};