属性 'contactId' 在类型 'any[]' 上不存在

Property 'contactId' does not exist on type 'any[]'

我正在尝试过滤一个名为 'notes' 的对象数组。当我尝试这样做时,出现错误: 属性 'contactId' 在类型 'any[]' 上不存在。

notes: Array < any > [] = [];
currentNotes: Array < any > [] = [];

notes.forEach(element => {
  //Filter out notes without contact  
  if (element.contactId != null) {
    this.currentNotes.push(element);
  }
})

你定义数组的数组,你的代码应该看起来像这样

   notes: Array < any > = [];
    currentNotes: Array < any > = [];

    notes.forEach(element => {
      //Filter out notes without contact  
      if (element.contactId) {
        this.currentNotes.push(element);
      }
    })

比较

之前先检查element是否包含contactid
notes: Array < any > [] = [];
    currentNotes: Array < any > [] = [];

    notes.forEach(element => {
      //Filter out notes without contact  
      if (element.contactId&&element.contactId != null) {
        this.currentNotes.push(element);
      }
    })