map() method in jQuery


The map() method creates a new array with the results of calling a function for every array element.The map() method calls the provided function once for each element in an array, in order.

Syntax
array.map(function(value, index))

Example

The following example shows, how to display a array elements into different h1 tags using map() method in jquery.

 
<html lang="en">
 <head>
  <title>.map() in jQuery</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
 </head>
<body>
 <div id='output'>
 </div>
 <script>
  $(document).ready(function(){
    a=["Ram","Tom","Sam"];
    var res=a.map(function(value,index){
      return "<h1>"+value+"</h1>";
    });
    $("#output").html(res.join(""));
  });
 </script>
</body>
</html>
Try it Yourself
Demo