Skip to content

How to get next value under ForEach function #342

@flenoir

Description

@flenoir

Hi,

I did check all repo and couldn't find an answer about this.

Mu code is like below and i'm using "ForEach" to loop on a json object. I'd like to compare the current value to the next one to check if the values are the same.


	result2 := gjson.Get(json2, "hits.hits")

	result2.ForEach(func(key, value gjson.Result) bool {
		leresultatTmj := newEntiteTmj(value.Get("_source.kubernetes.labels.mycode").String(), value.Get("_source.kubernetes.myteam").String())
		println("current results are : ", leresultatTmj.composantTmj, leresultatTmj.team)
		return true // keep iterating
	})

How can i access the next value ? i did try to use "key" valueassociated to "value" but couldn't find a proper way.

Is it possible to do so ?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions