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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:33:27+00:00 2026-05-26T10:33:27+00:00

I have an array [#page1, yield, yield, yield, #page2, yield, #page3 ] I want

  • 0

I have an array ["#page1", "yield", "yield", "yield", "#page2", "yield", "#page3" ]

I want to iterate through the array top-down, starting at the last yield and looking for the next occurence of an element not being yield (which is #page2).

This is what I have:

var longest = ["#page1", "yield", "yield", "yield", "#page2", "yield", "#page3" ],
    longestLen = longest.length;
for (i = longestLen-2; i>=0; i--) { 
     if ( longest[i] != "yield") {
          var gotoPage = longest[i];
          }
    }

I’m starting at i=5 (6 iterations) and checking if the element is not yield. However, the current way runs through all 6 iterations, so I end up with the page#1 instead of the #page2. I don’t know how I can stop the iterations.

Using return did not work, what other means are there? Is lastIndexOf something I could use?

Thanks for help!

  • 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-26T10:33:28+00:00Added an answer on May 26, 2026 at 10:33 am

    you’re looking for the breaktutorial keyword, which breaks out of a loop.

    if ( longest[i] != "yield") {
        var gotoPage = longest[i];
        break; // wont iterate any further in the for(...) loop
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose we have following pages and their serving weightage: Page1 50% Page2 20% Page3
I have an array that I want on multiple pages, so I made it
VISUAL C++ Question Hi, I have array of 3 elements and I want to
I want to insert all divs which have the class .page into an array,
I have page1.php that uses a form to send the following data: <form action=page2.php
I have an array of javascript objects and I want to press a submit
Hi have an array of cities and want to create a google map using
I have array of image in scroll view. I want to upload bigger image
I have an array of checkboxes on the page and I want to save
I have an array of arrays, with the following structure : array(array('page' => 'page1',

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.