Find Last Index In Array Javascript Function