question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Accessing object property using indexer notation

See original GitHub issue

Based on the docs I was under the impression I can access a property of an object using either the simple dot-notation or the indexer-notation, e.g. if I have an object foo with a property name, I thought both of these are legal:

{{ foo.name }}
{{ foo["name"] }}

But a sample of my code that uses the indexer notation fails with this exception:

Unhandled Exception: Scriban.Syntax.ScriptRuntimeException: Expecting a list. Invalid value `Foo.Model.Attribute/Attribute` for the target `att` for the indexer: att[key]

Where att is a global variable of the type Foo.Model.Attribute – a native .NET type.

Do I misunderstand the usage?

The reason I was trying to resort to the index-notation is that the Attribute type has a property named Null which surfaces as null in the scriban template and seemingly causes a conflict with the reserved keyword of the same name. For example, both of these are failing:

{{ if att.null }}Not Required{{ end }}

{{ if att["null"] }}Not Required{{ end }}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
xoofxcommented, Mar 13, 2019

Should be fixed by commit 548998c that will be part of 2.0.1+

0reactions
xoofxcommented, Jan 21, 2019

If that’s the case, is that by design?

I don’t remember 😉 (currently don’t have time to look into the code)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Property accessors - JavaScript - MDN Web Docs - Mozilla
Property accessors provide access to an object's properties by using the dot notation or the bracket notation.
Read more >
How to access object using index notation - javascript
You can access on the inner block like this : cond[i]['Created ->OFP']. Example with loop : var cond = [{ "locality": "Dwarka", ...
Read more >
Dot Notation vs Bracket Notation for Object Properties
There are multiple ways to access object properties in JavaScript. But two common ones are dot notation and bracket notation.
Read more >
How to Access Object Properties in JavaScript in Three Ways
You use the dot notation to access the property you want. After that, you use square brackets and index to get the item...
Read more >
How to Access Object Properties Dynamically Using Bracket ...
Index types tell the compiler that the given property or variable is a key representing a publicly accessible property name of a given...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found