-
Notifications
You must be signed in to change notification settings - Fork 13
Iterations
hazzard993 edited this page Mar 4, 2019
·
2 revisions
Object and array iteration in TypeScript.
let object = { x: 0, y: 0 };
for (const key in object) {
const value = object[key];
print(key, value);
}
let array = [0, 1, 2];
for (const item of array) {
print(item);
}
or
let array = [0, 1, 2];
array.forEach(num => print(num));
array.map(num => print(num));
array.filter(num => print(num));
The latter option uses LuaLibs
Be sure not to name your coroutine "coroutine"
function * testCoroutine() {
yield [1, 2];
yield [3, 4];
yield [5, 6];
}
for (const [x, y] of testCoroutine()) {
print(x, y);
}