<script>
const container = [];
const push = (function(container) {
const alreadyInContainerIndex = {};
const checkItem = function(item) {
return alreadyInContainerIndex.hasOwnProperty(item.id);
};
return function(data) {
if (data && checkItem(data)) return;
container.push(data)
if (data) alreadyInContainerIndex[data.id] = true
}
})(container);
push(null);
push(null);
push({id : 1})
push({id : 1})
document.write(JSON.stringify(container, null, 4))
</script>