How to check if value exists in this JavaScript array?

后端 未结 5 1674
南旧
南旧 2021-01-02 00:43

I have a JavaScript array, where each new item added to the array gets the next incremental number. An example would be as follows (I hope Im writing this correctly):

<
5条回答
  •  没有蜡笔的小新
    2021-01-02 01:13

    function IsIdInArray(array, id) {
      for (var i = 0; i < array.length; i++) {
        if (array[i].id === id)
          return true;
      }
      return false;
    }
    
    var result = IsIdInArray(ArrayofPeople, 820);
    

提交回复
热议问题