ColdFusion 8中是否有类似于ColdFusion 9中的ArrayFind的功能? [英] Is there a function similar to ArrayFind from ColdFusion 9 in ColdFusion 8?

查看:28
本文介绍了ColdFusion 8中是否有类似于ColdFusion 9中的ArrayFind的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在工作中与另一位程序员同事交谈,我们使用 ColdFusion.他告诉我只是在一个数组中查找一个值我必须做一个完整的循环?ColdFusion 8 中是否没有简单地在数组中查找值的功能?

I was talking with another fellow programmer at work and we use ColdFusion. He is telling me simply look for a value in an array I have to do a whole loop? Is it true there is no function in ColdFusion 8 to simply look for a value in an Array?

推荐答案

arrayFind() 在 ColdFusion 8 中不存在.但是,您不需要循环.有两种方法:

arrayFind() doesn't exist in ColdFusion 8. However, you don't need to loop. There are two ways:

利用 ColdFusion 数组实现接口 java.util 的事实.列表:

Take advantage of the fact that ColdFusion arrays implement the interface java.util.List:

<cfset valueToFind = 1>
<cfset array = [1,2,3]>
<!--- add one because CF does 1 based vs. Java 0 based arrays --->
<cfset position = array.indexOf(valueToFind) + 1> 

使用列表操作:

<cfset valueToFind = 1>
<cfset array = [1,2,3]>
<cfset position = listFind(arrayToList(array), valueToFind)>

第一种(Java List)方法更快.

The first (Java List) method is faster.

这篇关于ColdFusion 8中是否有类似于ColdFusion 9中的ArrayFind的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆