I'm trying to check if something exists in an array.
here is where I make the object...
function makeEventObject(eventName, idzName, classzName) {
function eventDetails(eventName, idzName, classzName) {
this.eventName = eventName;
this.idzName = idzName;
this.classzName = classzName;
}
let eventObject = new eventDetails(eventName, idzName, classzName);
console.log(Object.getOwnPropertyNames(eventObject));
console.log(eventObject.idzName);
// console.log(eventObject);
return eventObject;
}
I can access the eventObject.keys or eventObject.properties >> console.log The thing I can't figure out, is, I want to push it to an array. But with conditions. If its already in the array, then don't add. But the conditions are also based on on other eventObject.properties. for example: the 1st check is to see if it exists in the array. Because the array is empty initially it should return = undefined, SO add the 1st item. But when the second item comes through, if the eventObject.idZName && the eventObject.classzName is the same as the 2nd do NOT add. if, the .idZname is different, and the .classZname is the same, replace the array element with same .classZname. if the both the .classZname and .idZname are different from what's in the array or undefined. ADD.
its a series of filters, that I came to see to get functional. below are the push to array functions and checker functions. I tried to put both into the same function, but i kept getting .push() errors.
function makeEventList(eventObject) {
eventList.push(eventObject);
console.log(eventList);
let a = eventList.length;
console.log(a);
}
function eventChecker(eList, eventObject){
var exists = eList.find(function(eventObject){return eventObject.eventName === eList[eventObject.eventName];});
console.log(exists);
}
Any Ideas...and what I'm doing wrong? so far tried IF statements, .includes(), .filter(), .each().
currently I'm getting cannot read property of 'find;.. a live copy is available at fiddle -> https://jsfiddle.net/j1xtvmLy/461/