Warm tip: This article is reproduced from serverfault.com, please click

Find a value within array of structures

发布于 2020-12-31 10:31:25

this might have been asked before, but didn't quite find... or what I found was old.

I have an array of structures like so:

enter image description here

Isn't there a CFML function that will allow me to check if "test@email.com" already exists under any of the structures "toAddress" ? I can obviously loop my array, check and break if found, but wondering if something already exists for this ?

Thank you. Pat

Questioner
Pat
Viewed
0
Scott Stroz 2020-12-31 21:50:25

You can use arrayFind() with a callback function. Using your data structure above and assume the array is named myArray

if( 
    !arrayFind( myArray, function( item ){
        return item.toAddress == 'test@email.com'
    })
){
    // do stuff if address is not used.
}