How to make links at runtime

I’m trying to make a system so that for each item in an array, a link is created. I’m not sure how to do this though.

Which story format are you using? What, specifically, do you mean by “item in an array”?

Here are some simple examples in the meantime for SugarCube and Harlowe.

SugarCube

With an array of passage names like the following:

<<set $passages to ["North", "West" ,"South"]>>

The following code would make links out of them:

<<for _passage range $passages>>
<<link _passage _passage>><</link>><</for>>

The following is equivalent, but will also erroneously create a passage named _passage in Twine 2 due to its automatic passage creation feature:

<<for _passage range $passages>>
[[_passage]]<</for>>

Harlowe

With an array of passage names like the following:

(set: $passages to (a: "North", "West" ,"South"))

The following code would make links out of them:

(for: each _passage, ...$passages)[
(link-goto: _passage)]

The following is equivalent, but will also erroneously create a passage named _passage in Twine 2 due to its automatic passage creation feature:

(for: each _passage, ...$passages)[
[[_passage]]]

Oops. By item, I mean index, and I’m using sugarcube.