Check if js.Valu exists

In the JavaScript code, I’ve:

request.onsuccess = function(event) {
    var cursor = event.target.result;
    if(cursor){ }
}

In my equivalent GO code, I wrote:

ReadAll = js.FuncOf(func(this js.Value, args []js.Value) interface{} {
		defer ReadAll.Release()
		cursor := this.Get("result")

		if cursor { }
}

But while compiling, I got:

non-bool cursor (type js.Value) used as if condition

Ho can I check if the related js.value exists or no?

Perhaps you wantbto use Truthy method?

1 Like

Thanks, it is exactly what solved my issue js package - syscall/js - pkg.go.dev