Description

Iterates over every entry of the array and calls the closure function to work on the element of the array. The returned value will be set at the same index in a new array and the new array will be returned

Returns

Array

Syntax

ArrayMap(array, function(item [,index, array]))

History

ColdFusion 11: Added this function.

Attributes

Attribute

Req/Opt

Default

Description

array Required   The input array.
function Required  

Closure or a function reference that will be called for each iteration. The arguments passed to the callback are:

  • item: item in the array
  • index: index of the array
  • array: a copy of the original array. Note changes to this array will not be reflected in the original array.

Example

<cfscript>
	myArray=ArrayNew(1);
	myArray = [ 1,5,7,9,11 ];
	newArray = arrayMap(myArray, function(item){
   				return item;
				});
	writeDump(newArray);
</cfscript>

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy