Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7746429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:16:34+00:00 2026-06-01T10:16:34+00:00

Whenever I use a for … in loop, the index variable of the loop

  • 0

Whenever I use a for … in loop, the index variable of the loop always seems to be in the variables scope.
For example if I have a component with a method that uses this loop:

for(key in params){  
    writeOutput(key);  
}

The variable ‘key’ will be placed in the variables scope. If I already have declared a variables.key anywhere in the component, this value gets overwritten when I use this for … in loop. What I actually need is something like this:

for(var key in params){
    writeOutput(key);
}

This however throws a parsing error.

Is there any way to put the for … in index in a different scope then the variables scope?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:16:36+00:00Added an answer on June 1, 2026 at 10:16 am

    The default scope inside CFCs is variables if you don’t var beforehand.

    You have to var the index outside the loop like so:-

    var key = "";
    
    for(key in params){
        writeOutput(key);
    }
    

    An alternative approach, to avoid varring everything within your functions, is to declare your variables within a “local” structure. In CF9 a local scope is built in but for CF8 or below do something like this:-

    var local = structNew();
    
    for(local.key in params){
      writeOutput(local.key);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Whenever I use WCF, I always try to make immutable classes that end up
I have a FULLTEXT index called cart_product_fti on a table Whenever I use it,
I have problem with using dequeueReusableCellWithIdentifier method. Whenever I use this one, one cell
It seems like whenever I use the Command Pattern, it always leads to a
Whenever I use a variable name that stands for a primary key as int
Whenever I use the signal/slot editor dialog box, I have to choose from the
Whenever I use Html.ActionLink it always Html encodes my display string. For instance I
Whenever I use the splice method in Javascript like so: Array.prototype.mymethod = function() {
I have encountered a very strange issue. Whenever I use the .NET membership provider
Whenever I use the ORM deisgner in LinqToSql I have real problems trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.