簡體   English   中英

遍歷所有obj的數組而不遍歷所有對象

[英]iterate through an array of all objs not searching through all

我想遍歷所有對象數組,並通過簡單的if語句搜索字段值。

以下是我所擁有的,但似乎並沒有搜索我的所有obj數組。 我想搜索所有的obj數組,以查找某個屬性為某個值的實例,並僅顯示具有匹配值的obj。

$.each(data.arrayofObjs, function (index, item) {

  if (data.arrayofObjs[0].objsIDfield == 3222) {
     window.alert("correct!");

  } else {

  }
});

如果始終選擇第一個即第0個元素,那么遍歷數組有什么用。

data.arrayofObjs[0].objsIDfield

更改為

data.arrayofObjs[index].objsIDfield

如果您已經將索引傳遞給函數,請執行以下操作:

  $.each(data.arrayofObjs, function (index, item) {

    if (item.objsIDfield == 3222) {
        window.alert("correct!");

    } else {

   }
 });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM