我想在 javascript 数组中执行搜索,显示与查询相关的所有结果,相当于以下 SQL 语句:
"SELECT * FROM table WHERE column LIKE input"
这是一个例子:
var array = [];
array[0] = "Apple";
array[1] = "Apricot";
array[2] = "Pear";
array[3] = "Peacock";
假设我的查询字符串是“ap”,它将按以下顺序返回结果:
1. "Apple"
2. "Apricot"
query = "p"
result:
1. "Pear"
2. "Peacock"
3. "Apple"
4. "Apricot"
query = "r"
result:
1. "Apricot"
2. "Pear"
这在javascript中可能吗?如何?