Working with arrays

Asked

Viewed 25 times

-3

I have this array:

{tag: "teste"}

how do I save the test word in a variable?

  • Dude, this is a js object, actually if you want to access this variable just put a point concatenated to the variable name and the key you’re using in the tag case. then let’s assume that you have obj = {tag: "test"}; vc can assign the other variable with; var = obj.tag;

  • 1

    Learn more about ARRAYS https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array and on OBJECTS https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Trabalhando_com_Objetos

1 answer

1

This {tag: "teste"} is a json object, not an array. If you receive a named object with this value, then just look for the field name: var a = xpto.tag. Hugs and follows the leader.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.