sorry if i mislead you with my earlier comment.
without if condition seems to be more proper, i just said i hope in gltf there will never be situation when extra.targetNames is different length than targets.
it will not break code using this, but it would lead to odd issues without any exceptions.
like i would got shape keys in blender: 1:a, 2:b, 3:c, 4:d
and 1:a,2:c,3:d would be in targetNames,
then a = a, b = c, c = d that would be very unpredictible.
i understand probably it will never happen anyway, because extra.targetNames will probably always be same length as targets.
but anyway some exception or severe log should be thrown too.
i red https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md
but i was unable to find anything about targetNames length or key relation.
Anyway Its just my personal opinion, but as i know its required to know something is wrong. (much easier to find issue later)