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

Can Array.Foreach key=array.index? #248

Closed
itmaple opened this issue Nov 2, 2021 · 3 comments
Closed

Can Array.Foreach key=array.index? #248

itmaple opened this issue Nov 2, 2021 · 3 comments

Comments

@itmaple
Copy link

itmaple commented Nov 2, 2021

array.ForEach(func(key, value gjson.Result) bool {
    // key -> 0 or 1 or 2 ...
}
@tidwall
Copy link
Owner

tidwall commented Dec 1, 2021

Yes. I think that this can be made so. While an array does not really have a key like an object, we can easily produce one behind the scenes.

I think for now we should only fill the key.Num and key.Type fields. We'll leave the key.Raw and others empty.

This'll allow for key.String() and key.Int() to return the string and integer representation of the array index.

tidwall added a commit that referenced this issue Dec 1, 2021
@tidwall
Copy link
Owner

tidwall commented Dec 1, 2021

I just added this feature. Thanks for the suggestion.

@itmaple
Copy link
Author

itmaple commented Dec 3, 2021

Yep!Thanks.

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

2 participants