array.map((val, index, {length}) => if (index + 1 == length) { alert("last element") } else { alert("element #"+index) })