How to iterate over array indices in zsh?

In bash we can iterate over index of an array like this

~$ for i in "${!test[@]}"; do echo $i; done

where test is an array, say,

~$ test=(a "b c d" e f)

so that the output looks like

a
b c d
e
f

However, when I do the same in zsh I get an error:

➜ ~ for i in "${!test[@]}"; do echo $i; done
zsh: event not found: test[@]

What is going on?

What is the proper way of iterating over indices in zsh?

Go to Source
Author: Gao Zheng

How can I display Only the first Array/Object?

By using WordPress REST Api

./wp/v2/users/?_fields=id&orderby=id&order=desc

Result

[{“id”:13},{“id”:12},{“id”:11},{“id”:10},{“id”:9},{“id”:8},{“id”:6},{“id”:5},{“id”:4},{“id”:3}]

What I want?

I just want to display [{“id”:13},
Means, I want to limit it to only 1 array Using REST API. Any one have solution on this?

Go to Source
Author: Muhaza