TypeScript - Function Returning an Array


Advertisements


Allows a function to return an array.

Example

function disp():string[] { 
   return new Array("Mary","Tom","Jack","Jill") 
} 
 
var nums:string[] = disp() 
for(var i in nums) { 
   console.log(nums[i]) 
}

On compiling, it will generate following JavaScript code −

//Generated by typescript 1.8.10 
function disp() { 
   return new Array("Mary", "Tom", "Jack", "Jill"); 
} 
var nums = disp(); 
for (var i in nums) { 
   console.log(nums[i]); 
}

Its output is as follows −

Mary 
Tom 
Jack 
Jill

typescript_arrays.htm

Advertisements