What is map in javascript?

Map example in javascript:
"map() method returns a new array. map method works with an array and its parameter must need a call back as a function."
Map() method needs a callback function or object. It's the return value in the array. It works with value if you don't have value then it does not work. Also, this method maintains the value of the original array.  This example created a new array Or you can send dynamic value. Then I have used a map with this new array, here I have passed a function getMap(), then the result will be shown as below:

Your Result:

Map example in javascript:

const counting = [1, 4, 9, 16];

const counts1 = counting.map(ab => ab * 3);
// Array [3, 12, 27, 48]

const colors = ["Red", "blue", "Black"];

// pass a function to map
const newColors = colors.map(ab => ab + " Light");

// Array ["Red Light", "blue Light", "Black Light"]

                var numericArray = ["abc""Hello"124];
                var newArrValue = numericArray.map(getMap)
                function getMap(num) {
                  return num + ': ';
Result will be:

No comments:

Note: Only a member of this blog may post a comment.

Copyright Reserved to Anything Learn. Powered by Blogger.