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 6620885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:09:54+00:00 2026-05-25T21:09:54+00:00

This is what I want to do: cycle through a complex data structure and

  • 0

This is what I want to do: cycle through a complex data structure and if one of the elements meets some condition, return it. But I don’t think it’s possible to return from within an ‘if’ that’s within my for loop. What’s the best practice? Thanks.

function findIt(x) {
    for (i in someDataArray) {
        v = someDataArray[i];
        if (*v meets some condition*) {
            return v;
        }
    }
}
  • 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-05-25T21:09:55+00:00Added an answer on May 25, 2026 at 9:09 pm

    It’s perfectly legal to issue return statement from within an if.

    The only issue here is what happens if it’s not found? Here the function will implicitly return undefined. It may be better to make this explicit. This is a matter of style though.

    function findIt(x) {
        for (i in someDataArray) {
            v = someDataArray[i];
            if (*v meets some condition*) {
                return v;
            }
        }
        return undefined;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, is there a way to 'cycle' through child elements. i.e.: <ul> <li>some text</li>
I want to apply cycle to the div block with dynamic content. This content
I want this for some conditional compilation code that will run in all IE's
I have 4 banner images, and I want to cycle through them using a
I want to cycle through each page of a paginated model's index. I'm using
The jQuery plugin cycle looks for elements of class slideshow . I want to
I have one class that inherits another. I want to use reflection to cycle
I have a map from jquery: 82|81|83|84|85|86|87|88|89 I need to cycle through this map
Is there a way to cycle through open windows. I quite often use this
I want to be able to cycle through the active processes on the system

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.