Home Java Java-get-example JavaScript array map
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

JavaScript array map

Advertisement
In this Tutorial we want to describe you a code that help you in understanding JavaScript array map.

JavaScript array map

     

In this Tutorial we want to describe you a code that help you in understanding JavaScript array map. For this we are using a JavaScript language as script language. The function name functionmakeplural accept single as parameter variable, the variable single accept the list of  value and store in it. Finally the document .write ( ) method print all the list of element in a singular form. The for loop evaluate the length of the element in singular form and the document. write print the length of element. The Single variable map the singular element to plural and store in variable plural. The document.write print the element in plural form. The for loop return you the number of times your script runs and the length of the plural element in the list printed by the docment.write ( ) method.

Arraymap.html

<html>
  <head>
  <title>Array Map</title>
  
  </head>
  <body>
  <script language="javascript" type="text/javascript">
  function makePlural(single)
  {
  return single.replace(/o/g, "e");
  }
  var singles = ["Foot""Goose""Moose","Choose","Toose"];
  document.write("<b>"+"Elements in singular form are: "+"</b>"+"<br>");
  document.write("======================"+"<br>");
  for(var i=0;i<singles.length;i++){
  document.write(singles[i]+"<br>");
  }
  var plural = singles.map(makePlural);
 document.write("<b>"+"Elements in Plural form are: "+"</b>"+"<br>");
 document.write("======================"+"<br>");
  for(var i=0;i<plural.length;i++){
  document.write(plural[i]+"<br>");
  }
  </script>
  </body>
</html>

Output of the program

Download Source code

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 6, 2008

Related Tutorials

Ask Questions?    Discuss: JavaScript array map  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com