Compare Revisions

Array.prototype.map()

Change Revisions

Revision 517141:

Revision 517141 by fscholz on

Revision 518405:

Revision 518405 by Dan-Dascalescu on

Title:
Array.prototype.map()
Array.prototype.map()
Slug:
Web/JavaScript/Reference/Global_Objects/Array/map
Web/JavaScript/Reference/Global_Objects/Array/map
Tags:
"ECMAScript5", "JavaScript 1.6", "Array", "prototype", "JavaScript", "Method"
"ECMAScript5", "JavaScript 1.6", "Array", "prototype", "JavaScript", "Method"
Content:

Revision 517141
Revision 518405
t80    <h3 id="Example.3A_Pluralizing_the_words_(strings)_in_an_arrat
>y"> 
81      Example: Pluralizing the words (strings) in an array
82    </h3>
83    <p>
84      The following code creates an array of "plural" forms of no
>uns from an array of their singular forms. 
85    </p>
86    <pre class="brush: js">
87function fuzzyPlural(single) {
88  var result = single.replace(/o/g, 'e');  
89  if( single === 'kangaroo'){
90    result += 'se';
91  }
92  return result; 
93}
94 
95var words = ["foot", "goose", "moose", "kangaroo"];
96console.log(words.map(fuzzyPlural));
97 
98// ["feet", "geese", "meese", "kangareese"]
99</pre>

Back to History