Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    May 2012
    Posts
    89
    Thanks
    51
    Thanked 0 Times in 0 Posts

    How to put variable in an object?

    Gidday

    I have an AJAX object:

    data: {lastOne:171, superVar:'treat'},

    if I also have...

    var myLastOne = 171;

    ...how do I put that var into the object to make the object dynamic?

    so...

    data: {lastOne:myLastOne , superVar:'treat'},

    Thanks for your time and help.

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    Yes so

    But it will not be dynamic. It will contain only the current value of myLastOne. If you change myLastOne, the content of data will not change automatically.

  • #3
    New Coder
    Join Date
    May 2012
    Posts
    89
    Thanks
    51
    Thanked 0 Times in 0 Posts
    Thanks Devnull

    That all made sense - much appreciated.

  • #4
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,133
    Thanks
    12
    Thanked 332 Times in 328 Posts
    Quote Originally Posted by devnull69 View Post
    But it will not be dynamic. It will contain only the current value of myLastOne. If you change myLastOne, the content of data will not change automatically.
    except when myLastOne is an object, but that’s not the case here. (just to have it mentioned)
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •