【发布时间】:2017-05-21 13:31:42
【问题描述】:
我想检查data.objectId 是否已经存在于数组msgArr 中。为此,我正在运行以下代码:
var exists = msgArr.objectId.includes(data.objectId);
if(exists === false){
msgArr.push({"objectId":data.objectId,"latLont":data.latLont,"isOnline":data.isOnline});
}
数组如下所示:
var msgArr = [
{isOnline:true,latLont:"123",objectId:"on0V04v0Y9"},
{isOnline:true,latLont:"1",objectId:"FpWBmpo0RY"},
{isOnline:true,latLont:"48343",objectId:"Qt6CRXQuqE"}
]
我收到以下错误:
无法读取未定义的属性“包含”
【问题讨论】:
-
msgArr是一个数组。它没有objectId。 -
@DaveNewton 它有..
-
@Folky.H:那你就没有问题了。
-
因为
msgArr是一个数组。它没有objectId。 -
如果您想知道如何搜索数组以查看是否包含具有特定 ID 的对象,请在 Google 上搜索,您会找到很多解决方案。
标签: javascript typescript ecmascript-6