- TypeScript Tutorial
- TypeScript - Home
- TypeScript - Overview
- TypeScript - Environment Setup
- TypeScript - Basic Syntax
- TypeScript - Types
- TypeScript - Variables
- TypeScript - Operators
- TypeScript - Decision Making
- TypeScript - Loops
- TypeScript - Functions
- TypeScript - Numbers
- TypeScript - Strings
- TypeScript - Arrays
- TypeScript - Tuples
- TypeScript - Union
- TypeScript - Interfaces
- TypeScript - Classes
- TypeScript - Objects
- TypeScript - Namespaces
- TypeScript - Modules
- TypeScript - Ambients
- TypeScript Useful Resources
- TypeScript - Quick Guide
- TypeScript - Useful Resources
- TypeScript - Discussion
TypeScript - Function Returning an Array
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