Wednesday, October 12, 2011

Returning Multiple Values in JAVASCRIPT

function myFunction() {
  var result = testFunction();
   alert(result[0]);//returns "1"
   alert(result[1]);//returns "2"
   alert(result[2]);//returns "3"
}

//This function returns multiple values(a,b,c) in the form of array.
function testFunction() {
  var a="1",b="2",c="3";
    return [a,b,c]
}

No comments:

Post a Comment