如何在定义的数组中查找值

How to find a Value in the defined Array

跟进这个问题

我有一个可接受的答案,如果定义了数组,我会尝试获取值...

https://cffiddle.org/app/file?filepath=a5a33cf1-1304-4423-ad18-f77a7ea14c98/06ec1e7f-3de5-41bc-b155-3eff2afc8a0f/a420c091-6f53-4ef3-882d-50506284349e.cfm

所以如果名称是“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>