I have an array with some values. How can I search that array using jquery for a value which is matched or close to it?
var a = [\"foo\",\"fool\",\"cool\",\"
You can use find method on array if you want to match any regex :
Array.find(x => /^left:/.test(x)
function find(arr) {
var result = [];
for (var i in arr) {
if (arr[i].match(/oo/)) {
result.push(arr[i]);
}
}
return result;
}
window.onload = function() {
console.log(find(['foo', 'fool', 'cool', 'god']));
};
It prints ["foo", "fool", "cool"]