如何解决如何在已定义的数组中查找值
关注此问题
trying to get the value of the struct inside an array
在我有一个可接受的答案的地方,如果数组已定义,我试图获取该值...
but my structure is like this
<cfscript>
x = [];
x[1] = {};
x[1]["name"] = "form";
x[1]["value"] = "100";
writedump(x);
</cfscript>
<cfset formIndex = ArrayFind(x,function(st){
return st.name == "form";
})>
<cfif formIndex eq 1>
<cfset value = x.filter((item) => ( item.value) )>
</cfif>
<cfdump value="#value#">
<cfdump var="#formindex#">
as i have to check form the name = "form" and then only i need to get the value of value field,else it should return me 0
解决方法
这看起来像是使用三元运算符。
<cfscript>
x = [];
x[1] = {};
x[1]["name"] = "form";
x[1]["value"] = "100";
formIndex = x.find((st) => (st.name == "form"));
result = formIndex ? x[formIndex].value : 0
</cfscript>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。