• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Difference between arrayContains() vs listContains()?

Community Beginner ,
Mar 15, 2019 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

371

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
community guidelines
Community Expert ,
Mar 17, 2019 Mar 17, 2019

Copy link to clipboard

Copied

LATEST

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.

Votes

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
community guidelines
Resources
Documentation