![](/img/trans.png)
[英]how to add additional object to a key that already references one or more objects?
[英]How to compare an input with one object key and value from an array with more objects with more key and values
我是編碼新手(一個月),在這里我有點卡住了。 創建一個自動完成,我試圖將輸入與一個 object 鍵和值從一個具有更多對象的數組中進行比較,該數組具有更多鍵和值。
這就是我到目前為止所擁有的。 但我有點卡住了。
成分是包含更多對象的數組,我在其中保存信息
$("#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");
}
}
});
如果您在 for 循環中使用了i > ingredient.length
在成分數組中有一個或多個項目,則您正在使用的循環將不會運行。 嘗試以下
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.