Skip to content

Update loop syntax for arrays and objects, deprecate $index and $key #3073

@chrisvfritz

Description

@chrisvfritz

Deprecating $index and $key

Both of these are being deprecated in favor of more explicit named indices and keys. This syntax is a bit magical and has limitations in nested loops. As a bonus, there will be two fewer points of syntax for newcomers to learn.

New array syntax

  • value in arr
  • (value, index) in arr (switched order of arguments to be more consistent with JavaScript's forEach and map)

New object syntax

  • value in obj
  • (value, key) in obj (switched order of arguments, partly to be more consistent with many common object iterators, such as lodash's)
  • (value, key, index) in obj (index will now be available in object iteration for visual purposes, such as table striping)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions