Skip to content

Latest commit

 

History

History
11 lines (9 loc) · 372 Bytes

mapping-with-an-index.md

File metadata and controls

11 lines (9 loc) · 372 Bytes

Mapping With An Index

If you're mapping over a collection and you need an index for each item, you can reach for map-indexed. The map-indexed function can be used like so:

> (def foods ["pizza" "hotdog" "chicken alfredo"])
#'cljs.user/foods
> (map-indexed (fn [idx item] (str idx " - " item)) foods)
("0 - pizza" "1 - hotdog" "2 - chicken alfredo")