Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: support accessing array elements #2

Open
mahendraHegde opened this issue Oct 18, 2024 · 0 comments
Open

Feature Request: support accessing array elements #2

mahendraHegde opened this issue Oct 18, 2024 · 0 comments

Comments

@mahendraHegde
Copy link

Currently there is no way to access array elements
ex:

const tpl = require('nano-var-template')()
console.log(tpl("Hello {users[0].name}!", {users:[{name: "Jane Doe"}]}))

Proposal

  1. support accessing all elements of array using a delimiter(ex: $) as index, concat multiple items with \n or with a configurable option
console.log(tpl("Hello {users[$].name}!", {users:[{name: "Jane Doe"},{name: "John Doe"}]}))
// Hello Jane Done \n John Doe
  1. support accessing specific elements of array
console.log(tpl("Hello {users[1].name}!", {users:[{name: "Jane Doe"},{name: "John Doe"}]}))
// Hello John Doe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant