Access dynamic JSON Object key from variable given

Hello,

I have trouble getting a variable key request done:

I want to get userData.keyreq (wich is a variable and contains as example first name). The classic JS Methods to do things like this does not worked.

 async function cacheRequest(keyreq) {

      let userKv = "user-"+userId+"-"+keyreq

      let value = await PXKVNS.get(userKv)

      if (true) {
        console.log("Value "+userKv+" not found, create first request")

        // JSON GET USERDATA - if Cache
        const response = await fetch(url+'?uid='+userId)
        userData = await response.json()

        console.log('return '+userData.keyreq)
      }
  }

You’ll increase your chances of a faster response if you edit your post to place it in the category Developers > Workers.

1 Like

Hello, thank you, just done

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.