I'm using labels in my code. But javascript keeps complaining 'label is not a statement.'
function firstDuplicate(a) {
array1 = [];
b = a;
var val;
var valIndex;
var iCount = 0;
a.forEach(function(aLoop, aIndex) {
b.forEach(function(bLoop, bIndex) {
if (bLoop == aLoop) {
val = bLoop;
iCount = iCount++;
valIndex = bIndex;
} else { //I want to move evaluation to where I have label 'loop1'
break loop1;
}
});
obj = {
val: val,
index: valIndex,
count: iCount
};
array1.push(obj);
val = 0;
iCount = 0;
valIndex = 0;
loop1:
});
return array1;
}
console.log(firstDuplicate([2, 1, 3, 5, 3, 2]));
actual result is crashing; expecting js object be populated with 1) elements that occur > 1; index of the last occurence of the element; and count