📌  相关文章
📜  在javascript代码示例中搜索数组中的特定产品

📅  最后修改于: 2022-03-11 15:04:32.380000             🧑  作者: Mango

代码示例1
const products = [
    "Dell hardcore 129 laptop",
    "iphone 1Tb camera flashlight phone",
    "yellow laptop with balack camera",
    "Dell 1x59 lenovo commercial yoga Laptop",
    "LG supernove laptop dell",
    "HTC low price phone",
    "Dell purple color phone with Laptop"
]
//Searching laptop product inclues in the array
const searching = "laptop";
const output = [];
for (const product of products) {
    if (product.toLowerCase().indexOf(searching.toLowerCase()) !== -1) {
        output.push(product)
    }
}
console.log(output);
//Output: 
/* [
    'Dell hardcore 129 laptop',
    'yellow laptop with balack camera',
    'Dell 1x59 lenovo commercial yoga Laptop',
    'LG supernove laptop dell',
    'Dell purple color phone with Laptop'
  ] */