Skip to content
Reference > Methods

cycle(offset,choices)

Definition

Object cycle(Number offset, Object ... choices)

Description

Returns the nth object from choices where n is the offset + 1. If the offset is greater than or equal to the number of choices, n is calculated as (offset % number of choices) + 1.

Parameter Definition

Name Type Description
offset Number index into choices
choices Object...

Examples

1
2
3
4
String r1 = cycle(0,"zero","one","two","three"); // r1 == zero
String r2 = cycle(5,"zero","one","two","three"); // r2 == one
String r3 = cycle(-1,"zero","one","two","three"); // r3 == three
String r4 = cycle(17,"even","odd"); // r4 == odd