javascript - How to search an array in Jquery like SQL LIKE value% statement -


this question has answer here:

i have array values. how can search array using jquery value matched or close it?

var = ["foo","fool","cool","god","acl"]; 

if want search c, should return cool not acl.

how can achieve that?

use substring check if each string in array begins string searching for:

var strings = [ "foo", "cool", "acl" ]; var needle = "c";  (var = 0; < strings.length; ++i) {     if (strings[i].substring(0, needle.length) === needle) {         alert("found: " + strings[i]);     } } 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -