C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript TypedArray map() MethodThe 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:
Example 1JavaScript 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> Output: 2,4,6 Example 2JavaScript 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> Output: 10,1,3,5
Next TopicJavaScript TypedArray Object
|