the array), or omitted (in which case it refers to the start
or end of the array).
+ The `.[2]` syntax can be used to return the element at the
+ given index. Negative indices are allowed, with -1 referring
+ to the last element, -2 referring to the next to last element,
+ and so on.
+
The `?` "operator" can also be used with the slice operator,
as in `.[10:15]?`, which outputs values where the inputs are
slice-able.
input: '["a","b","c","d","e"]'
output: ['["d", "e"]']
+ - program: '.[-2]'
+ input: '[1,2,3]'
+ output: ['2']
+
- title: "`.[]`"
body: |
}
} else if (jv_get_kind(t) == JV_KIND_ARRAY && jv_get_kind(k) == JV_KIND_NUMBER) {
if(jv_is_integer(k)){
- v = jv_array_get(t, (int)jv_number_value(k));
+ int idx = (int)jv_number_value(k);
+ if (idx < 0)
+ idx += jv_array_length(jv_copy(t));
+ v = jv_array_get(t, idx);
if (!jv_is_valid(v)) {
jv_free(v);
v = jv_null();