frankframework / frontend-conventions

1 stars 0 forks source link

Is there an alternative for <some array>.indexOf() ? #3

Closed mhdirkse closed 1 month ago

mhdirkse commented 1 month ago

This method returns a value < 0 if the index is not found. During my work on frank-config-layout, I erroneously interpreted return value of zero. I treated zero as if the object I was searching was not present, while zero means that the object is at the beginning of the array.

Is there an alternative syntax for searching for which you can not make this error so easily? I would prefer a method that returns null or undefined if the object is not in the array.

Matthbo commented 1 month ago

This a question best looked up on Google or StackOverflow, this is not the place for advise or guidance on how to write better JS/TS code. However I recommend looking at .find()