TypeScript - Array map()


Advertisements

map() method creates a new array with the results of calling a provided function on every element in this array.

Syntax

array.map(callback[, thisObject]);

Parameter Details

  • callback − Function that produces an element of the new Array from an element of the current one.

  • thisObject − Object to use as this when executing callback.

Return Value

Returns the created array.

Example

var numbers = [1, 4, 9]; 
var roots = numbers.map(Math.sqrt); 
console.log("roots is : " + roots );

On compiling, it will generate the same code in JavaScript.

Its output is as follows −

roots is : 1,2,3
typescript_arrays.htm

Useful Video Courses


Video

Angular Essentials - Admin App, Typescript, Docker, c3.js

45 Lectures 4 hours

Antonio Papa

Video

NestJs: Modern ways to build APIs with Typescript and NestJs

41 Lectures 7 hours

Haider Malik

Video

Master Typescript : Learn Typescript from scratch

Best Seller

60 Lectures 2.5 hours

Skillbakerystudios

Video

Three.js and TypeScript

77 Lectures 8 hours

Sean Bradley

Video

TypeScript from Scratch: Go from zero to hero in TypeScript

77 Lectures 3.5 hours

TELCOMA Global

Video

Advanced TypeScript: Generic Search, Sorting and Filtering

19 Lectures 3 hours

Christopher Frewin

Advertisements