There isn't any specific way to compare objects in Javascript. So, if you are sure that the objects will be having same key-value pairs, you can use JSON.stringify() and compare the outcome. But, it may not be the exact solution to this problem.
So, here iteration will be better for the check. For that you can use the following code -
function itemExists(targetArray, targetObject) {
$.each(targetArray, function(i, item){
if(item.jobID === targetObject.jobID) {
return true;
}
});
return false;
}
function TicketList()
{
var self=this;
self.sample = ko.observableArray([]);
self.Getjobs = function () {
$.getJSON("/api/ticket", function (data) {
$.each(data, function (key, val) {
var newTicket = new Ticket(val.JobID, val.CreatedDateTime,val.JobTitle);
if(!itemExists(self.sample, newTicket)) {
self.sample.push(newTicket);
}
});
});
};
}