To verify the existence of data.objectId
in the array msgArr
, I am utilizing the following code snippet:
var exists = msgArr.some(item => item.objectId === data.objectId);
if(!exists){
msgArr.push({"objectId":data.objectId,"latLont":data.latLont,"isOnline":data.isOnline});
}
The current structure of the array is as shown below:
var msgArr = [
{isOnline:true,latLont:"123",objectId:"on0V04v0Y9"},
{isOnline:true,latLont:"1",objectId:"FpWBmpo0RY"},
{isOnline:true,latLont:"48343",objectId:"Qt6CRXQuqE"}
]
An error message that I encountered reads:
Cannot read property 'includes' of undefined