How to iterate arrays? #3325
-
Hi. I'm trying to figure out how I can iterate array in expressions.
fails with the following error (about the
|
Beta Was this translation helpful? Give feedback.
Answered by
josdejong
Nov 21, 2024
Replies: 1 comment 1 reply
-
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" |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
evil-shrike
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: