/ Keys and Iterators
DEMO | DOWNLOAD | DEPLOY | SEARCH
Login

Jsi provides limited support for iterators, in the form of for loops and the method keys():

cat > keys.jsi<EOF
var x = {a:1, b:2};
;x.keys();
var y = [1,2];
;y.keys();
EOF
jsish --U keys.jsi

which outputs:

x.keys() ==> [ "a", "b" ]
y.keys() ==> [ 0, 1 ]

However this doesn't really buy you much.

var y = [1, 2];
for (var i in y) { puts(i); }
for (var i of y.keys()) { puts(i); } // Same as above

Moreover in ECMA keys()) works very differently, eg:

var k = Object.keys(x);

And this works only for Objects: Array does not support keys().

In summary, iterators, other than for, are not really supported.

See Iterators on Stackoverflow.com