1 The `rindex()` function locates an element within a given array or a substring 2 position within a given string, depending on the type of arguments given. 3 4 Returns `null` if the given haystack argument is neither an array nor a string, 5 returns `-1` if the element was not found within the array or the substring was 6 not found within the string. 7 8 Returns the last found index position in all other cases. 9 10 -- Testcase -- 11 {% 12 let o = {}; 13 14 printf("%.J\n", [ 15 rindex([ 1, 2, "abc", 3, "abc", 1, 2 ], "abc"), // should return 4 16 rindex([ 1, 2, 3 ], 4), // should return -1 17 rindex([ [], {} ], {}), // should return -1 (strict equality) 18 rindex([ [], o ], o), // should return 1 (strict equality) 19 20 rindex("foobarfoobarfoobar", "arf"), // should return 10 21 rindex("test", "hello"), // should return -1 22 rindex("test", "test"), // should return 0 (needle = haystack length special case) 23 rindex("hello", "h"), // should return 0 (needle at haystack start special case) 24 rindex("test", ""), // should return 4 (zero length needle special case) 25 rindex("", ""), // should return 0 (zero length special case) 26 rindex("foo\0foo\0foo", "o\0f"), // should return 6 (binary safe) 27 28 rindex({ test: true }, true), // should return null 29 rindex(1234, 3), // should return null 30 ]); 31 %} 32 -- End -- 33 34 -- Expect stdout -- 35 [ 36 4, 37 -1, 38 -1, 39 1, 40 10, 41 -1, 42 0, 43 0, 44 4, 45 0, 46 6, 47 null, 48 null 49 ] 50 -- End --
This page was automatically generated by LXR 0.3.1. • OpenWrt