arrays - 类型“any[]”上不存在属性“contactId”
问题描述
我正在尝试过滤一个名为“notes”的对象数组。当我尝试此操作时,我收到错误消息:“any[]”类型上不存在属性“contactId”。
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);
}
})
推荐阅读
- c# - 如何从 Unicode 值创建表情符号字符串?
- vue.js - Vue 倒数计时器会在 console.log 上打印出来,但不会作为数据传递
- javascript - 将混合心情与黑色文本混合
- sql - 如果不存在关系,SQL 删除行
- javascript - JS - 过滤 Promise 对象
- multithreading - 使用 vs2017 时 std::thread::join() 在某些情况下挂起
- python - 如何解决 django 错误:raise TemplateDoesNotExist(', '.join(template_name_list), chain=chain)
- react-native - 如何在 react-native for android 中更改应用程序图标背景颜色
- python - Python查找多个字符串
- ios - 如何在 iOS 中找到自定义 UTI 应用程序支持?