I think you want the in operator, but I haven't tested the following:
in
for (let idx = 0; idx < collection.length; idx++) { const localIdx = idx; if (idx in collection) { collection[localIdx] = collection[localIdx] * 2; } }