JSFiddle - React, Tailwind, and code Playground
by David Thomas
JavaScript
function returnRandomValue (){
var values = ["someval1", "someotherval1", "someval2", "someval3", "tomato", "Pumice", "Spaghetti", "USS Enterprise", "Endymion", "Talkin' 'bout my generation", "Lorem ipsum", "running out of ideas, now..."];
return values[Math.floor(Math.random() * values.length)];
}
var mya = ["someval1", "someotherval1", "someval2", "someval3"],
returnedFunctionValue = returnRandomValue();
console.log('Searching for: "' + returnedFunctionValue + '."');
if (mya.indexOf(returnedFunctionValue) > -1) {
// the value held by the returnedFunctionValue variable is contained in the mya array
console.log('"' + returnedFunctionValue + '" at array-index: ' + mya.indexOf(returnedFunctionValue));
}
else {
// the value held by the returnedFunctionValue variable is not contained in the mya array
console.log('"' + returnedFunctionValue + '" not held in the array');
}