Created
June 27, 2018 16:01
-
-
Save neokoenig/e3a1e87ebf644d41f3ab2591a746a88e to your computer and use it in GitHub Desktop.
ArrayFind vs ArrayFilter as Member functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
products = [ | |
{"sku": "prod_one", "title": "Product One"}, | |
{"sku": "prod_two", "title": "Product Two"}, | |
{"sku": "prod_three", "title": "Product Three"}, | |
{"sku": "prod_four", "title": "Product Four"} | |
]; | |
skuToFind="prod_two"; | |
echo("========== Using Find as a Member Function"); | |
f = products.find(function(el) { | |
return el.sku == skuToFind; | |
}); | |
writeDump(f); | |
echo("========== Using Filter as a Member Function"); | |
x = products.filter(function(el) { | |
return el.sku == skuToFind; | |
}); | |
writeDump(x); | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment