0
var item1 = function() {
    var item1 = 'ITEM1 HERE';
    var item2 = 'THE REST HERE';

    if what_to_put_here() {
        return item1;
    } else if what_to_put_here {
        return item2;
    }
};

item1 = the first loop will have complete contents
item2 = from 2nd and the rest of the loop will have partial contents

Hi, I have a loop and I want the first loop to be different from the rest of the loop. I am still learning javascript by myself. Though google is there but I do not know the term/words to use. My questions, Is the code above is the right format? What are the functions to be used? Pls help. thanks in advance!

1 Answer 1

1

you can use boolean to trap the first iterate

like this.

var isFirstloop = true;

inside your loop. it should look like this

if(isFirstloop){
   isFirstloop = false;
   //ITEM 1 HERE
}else{
  //THE REST HERE
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.