跳转到主要内容

for-each

title: Iterate icons in icon set
types:
  IconifyJSON: '/docs/types/iconify-json.md'
  IconSet: './index.md'
functions:
  mergeIconSets: './merge.md'

forEach()

This function is part of [type]IconSet class in Iconify Tools.

Function [func]forEach() runs a custom callback for all icons in icon set.

Function supports asynchronous callbacks.

If you use synchronous callback, you can treat function as synchronous, or you can use [func]forEachSync() alias.

Usage

Function has the following parameters:

  • [prop]callback. Callback. See below.
  • [prop]type, [type]string[]. Optional. Icon types to iterate, default is [js]['icon', 'variation', 'alias'] (all items).

Callback

Callback can be synchronous or async. It has the following parameters:

  • [prop]name, [type]string. Icon name.
  • [prop]type, [type]string. Icon type (see below).

If callback returns false, function stops iterating icons.

Icon types

include libraries/tools/icon-set/icon-types

Example

src: libraries/tools/icon-set/for-each.ts
title: 'example.ts'
extra:
  - src: libraries/tools/icon-set/for-each.txt
    title: 'Result:'