Pierwszy duplikat JavaScript

function firstDuplicate(a) {
    let data = [];
    
    for (dup of a) {
        if (data[dup]) {
            return dup
        } else {
            data[dup] = dup
        }
    }
    return -1
}
Arrogant Anteater