
- 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
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
TypeScript - Passing Arrays to Functions
You can pass to the function a pointer to an array by specifying the array's name without an index.
Example
var names:string[] = new Array("Mary","Tom","Jack","Jill") function disp(arr_names:string[]) { for(var i = 0;i<arr_names.length;i++) { console.log(names[i]) } } disp(names)
On compiling, it will generate following JavaScript code −
//Generated by typescript 1.8.10 var names = new Array("Mary", "Tom", "Jack", "Jill"); function disp(arr_names) { for (var i = 0; i < arr_names.length; i++) { console.log(names[i]); } } disp(names);
Its output is as follows −
Mary Tom Jack Jill
typescript_arrays.htm
Advertisements