Making a function which can be called with an object literal I am working on a code snippet to make a function which can be called with an object literal. 

Problem area: If I do not need to track the product value, then a check has been placed for undefined. But do I really need to make check for each and every value if it's not there in the object literal?

trackProduct = function (args) {

      if(args.label == undefined) {
        value.push([args.category, args.action, args.value]);
      } else if(args.value == undefined){
        value.push([args.category, args.action, args.label]);
      } else {
        value.push([args.category, args.action, args.label, args.value]);
      }
};


I'm calling this function via below object literal. I have not passed the value parameter. 

trackProduct({
    category: elemcategory,
    action: elemaction,
    label: elemlabel
});


Do we need to check for undefined for all three parameters? Any suggestions on how to improve this code?
First, just a note: You check against undefined, but undefined is unfortunately not a keyword, meaning it's mutable. Better to use typeof something === 'undefined'

If I understand you right, you want to be able to "leave out" anyone of the object values. In that case, here's my take on the code (I'm returning an array, just for clarity)

function trackProduct(obj) {
  var keys = ['category', 'action', 'label', 'value'],  // properties to look for
      values = [],
      i, l, value;

  for(i = 0, l = keys.length ; i &lt; l ; i++) {
    value = obj[keys[i]];
    if(typeof value !== 'undefined') {
      values.push(value); // if the value's there, put it in the array
    }
  }

  return values;
}


This would work like so:

trackProduct({
  category: "foo",
  label:    "bar",
  value:    "23",
  ignored:  "something"
}); // =&gt; ["foo", "bar", "23"]