如何在定义的数组中查找值
How to find a Value in the defined Array
跟进这个问题
我有一个可接受的答案,如果定义了数组,我会尝试获取值...
所以如果名称是“form”,获取值的详细信息
代码
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>
跟进这个问题
我有一个可接受的答案,如果定义了数组,我会尝试获取值...
所以如果名称是“form”,获取值的详细信息
代码
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>