Skip to content

How to iterate arrays? #3325

Closed Answered by josdejong
evil-shrike asked this question in Q&A
Nov 21, 2024 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

The expression parser of mathjs has a different syntax for lambda functions than JavaScript, see docs:

https://mathjs.org/docs/expressions/syntax.html#functions

In your case, you can do:

const node = mathjs.parse("map(entries, f(t) = t.topic).join(';')");
let res = node.evaluate({entries: [ {topic: '1'}, {topic: '2'}]}); 
// res = "1;2"

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@evil-shrike
Comment options

Answer selected by evil-shrike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants