Skip to main content
mohammedwarishb7086
New Participant
Dec 9, 2024 5:54 PM UTC
Question

Index() function returns unexpected output

When I try index({1,2,3},{3,4},"") returns {3,null} whereas index({1,2,3},{3,4},{}) returns {3,1}. Looks like when curly brace is put in default parameter, when there is no 4th index, it goes back to start and picks the first index. i don't think this behaviour is captured in documentation either.

3 replies

mikes0011
Brainy
Dec 9, 2024 7:06 PM UTC

I believe this has been brought up before - I'm never clear on why this happens, but index() does some... funny(?) things in the background when given corner cases, so at this point I think this is sorta-expected behavior.

The Expression Guru
prakhars772510
Participating Frequently
Dec 10, 2024 3:33 AM UTC

This happens with many functions mostly I this it is considering " " as string rather than considering as null what I think from perspective but it's quite funny how these function in the cases.

Known Participant
Dec 10, 2024 2:07 PM UTC

I’ve come across this issue previously, and while I’m unclear on the reason, it seems that functions like index() exhibit strange behavior in some cases.