www.webdeveloper.com
Results 1 to 3 of 3

Thread: how to use property of object is argument in function

Hybrid View

  1. #1
    Join Date
    Mar 2014
    Posts
    2

    how to use property of object is argument in function

    i have this function :

    Code:
    var person={name:"tuna",age:"18"};
    function checkold(object,property){
           var data=object.property;
           return data;
    }
    alert(checkold(person,"age"); // display undefined
    it display undefined

    help me thank

  2. #2
    Join Date
    Oct 2012
    Location
    Croatia
    Posts
    255
    It's because you are actually trying to access a property of name property. There are two property access expressions in JavaScript.

    1. object.identifier
    2. object[expression]

    using the second expression you can access your object property like this:

    Code:
    var person={name:"tuna",age:"18"};
          
          function checkold(object,property) {
             var data=object[property];
             return data;
          }
          alert(checkold(person,"age")); //alerts 18

  3. #3
    Join Date
    Mar 2014
    Posts
    2
    it works
    thank u so much

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles