[英]How to compare an input with one object key and value from an array with more objects with more key and values
I am new to coding (one month) and in here and I am a little bit stuck.我是编码新手(一个月),在这里我有点卡住了。 Creating an autocomplete and i am trying to compare an input with one object key and value from an array with more objects with more key and values.
创建一个自动完成,我试图将输入与一个 object 键和值从一个具有更多对象的数组中进行比较,该数组具有更多键和值。
This is what I have so far.这就是我到目前为止所拥有的。 but I am a little bit stuck.
但我有点卡住了。
ingredients is the array with more objects where I keep the info成分是包含更多对象的数组,我在其中保存信息
$("#ingredientDetails").click(function () {
var searchQuery = $("input[type = 'text']").val();
for (var i = 0; i > ingredients.length; i++) {
if (searchQuery === Object.name(ingredients)) {
console.log("matching");
} else {
console.log("not matching");
}
}
});
The loop you are using will not run if you have one or more items in ingredients array as you have used i > ingredient.length
in your for loop.如果您在 for 循环中使用了
i > ingredient.length
在成分数组中有一个或多个项目,则您正在使用的循环将不会运行。 Try the following尝试以下
for (var i = 0; i < ingredients.length; i++) {
if (searchQuery === Object.name(ingredients)) {
console.log("matching");
} else {
console.log("not matching");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.