TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

JavaScript TypedArray map() Method

JavaScript TypedArray map() Method with example, join() method, javascript typedarray methods, keys() method, indexOf() method, includes() method, forEach() method, entries(), every(), find(), filter(), copyWithin() method etc.

<< Back to JAVASCRIPT

JavaScript TypedArray map() Method

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

NOTE: map() method does not change the actual array.

Syntax:

array.map(function(value, index, arr), thisValue)

Parameters:

Value(Required): The value of the current element.

Index(Optional): The array index of the current element.

arr(Optional): The array map() was called upon.

ThisValue(Optional): A value to be passed to the function to be used as its "this" value.

Return value:

A new array.

Browser Support:

Chrome Yes
Safari Yes
Firefox 1.5
Opera Yes

Example 1

JavaScript map() Method

<script type="text/javascript">
// JavaScript to illustrate map() method
var input=[1,2,3];
var output=input.map(function(input)
{
return input*2;
});
document.write("Array after using map() method the output is" );
document.write("<br>");
document.write(output);
document.write("<br>");
document.write("Actual array still remain the same ");
document.write("<br>");
document.write(input);
// expected output: arr[Output:2,4,6]
</script>
Test it Now

Output:

2,4,6

Example 2

JavaScript map() Method

<script type="text/javascript">
// JavaScript to illustrate map() method
var JavaTpoint = ['JavaTpoint','C','C++','RDBMS'];
//Determine the length of each name and save it in an array
var nameLengths =JavaTpoint.map(function(value, index, array)
{
var len =value.length;
return len;
});
document.write("Array using map() method the output is" );
console.log(nameLengths);
document.write(nameLengths);
document.write("<br>")
document.write("Actual array still remain the same ");
document.write(JavaTpoint);
// expected output: arr[Output:10,1,3,5]
</script>
Test it Now

Output:

10,1,3,5





Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf