Highlighted

Difference between arrayContains() vs listContains()?

Community Beginner ,
Mar 15, 2019

Copy link to clipboard

Copied

Hello everyone, I'm wondering if anyone can tell me pros/cons of either of these two functions? Which one is preferred and if there is any difference in performance/security, etc? I used arrayContains() thinking it's better/faster for validations some fields on the back end as well as reducing number of lines in situations like this:

<cfif userAccess eq 1>

       <!--- Do something --->

</cfif>

<cfif userAccess eq 4>

      <!--- Do something --->

</cfif>

Instead I used this:

<cfif arrayContains([1,4],userAccess)>

     <!--- Do something --->

</cfif>

​Would listFind() or listContains() ​be better fit in this case or not? Please if anyone have information about the differences let me know. Thank you.

TOPICS
Getting started

Views

265

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Difference between arrayContains() vs listContains()?

Community Beginner ,
Mar 15, 2019

Copy link to clipboard

Copied

Hello everyone, I'm wondering if anyone can tell me pros/cons of either of these two functions? Which one is preferred and if there is any difference in performance/security, etc? I used arrayContains() thinking it's better/faster for validations some fields on the back end as well as reducing number of lines in situations like this:

<cfif userAccess eq 1>

       <!--- Do something --->

</cfif>

<cfif userAccess eq 4>

      <!--- Do something --->

</cfif>

Instead I used this:

<cfif arrayContains([1,4],userAccess)>

     <!--- Do something --->

</cfif>

​Would listFind() or listContains() ​be better fit in this case or not? Please if anyone have information about the differences let me know. Thank you.

TOPICS
Getting started

Views

266

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Mar 15, 2019 0
BKBK LATEST
Adobe Community Professional ,
Mar 17, 2019

Copy link to clipboard

Copied

I would go by feel on this one. I would use, by default, if userAccess eq 1. I would go to the trouble of creating a userAccessList or userAccessArray only if there are more than a handful of userAccess values, say, more than 5. I would then do something like arrayContains(userAccessArray,userAccess).

The choice between  userAccessList and userAccessArray will depend very much on which one I will be able to reuse elsewhere in the code. After all, you gain performance not at one place but in the software as a whole.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 17, 2019 0