What I’m trying to do
I’m trying to write formula with handwritten object {...}
Things I have tried
correct
file.properties.isEmpty()
“invalid”
{}.isEmpty()
{"a": 1, "b": 2}.isEmpty()
Why they are invalid?
I’m trying to write formula with handwritten object {...}
file.properties.isEmpty()
{}.isEmpty()
{"a": 1, "b": 2}.isEmpty()
Why they are invalid?
You cannot create object literals in a formula, the docs seem to indicate you can but you cannot. What the docs are trying to communicate is that you can reference objects in frontmatter in notes. For example, given the following frontmatter:
---
obj:
thing1: "a value"
---
You can use obj.thing1 or obj["thing1"] to get "a value".
However, you can emulate creating an object literal using nested arrays, for example:
[
["a", 1],
["b", 2],
["c", 3]
].map(if(thing == value[0], value[1])).filter(value)[0]
Examples stolen from @sailKite on Discord here.
There’s also a real world example here if it’s helpful