WLJS LogoWLJS Notebook

Part

expr[[i]] or Part[expr, i] gives the ith part of expr.

expr[[-i]] counts from the end.

expr[[i, j, ...]] or Part[expr, i, j, ...] is equivalent to expr[[i]][[j]]....

expr[[{i1, i2, ...}]] gives a list of the parts i1, i2, ... of expr.

expr[[m;;n]] gives parts m through n.

Examples

Get the second element:

{a, b, c, d}[[2]]
(* b *)

Get the last element:

{a, b, c, d}[[-1]]
(* d *)

Get multiple parts:

{a, b, c, d}[[{1, 3}]]
(* {a, c} *)

Slice a list:

{a, b, c, d, e}[[2;;4]]
(* {b, c, d} *)

Please visit the official Wolfram Language Reference for more details.

On this page