To begin with, I'm a noob to JavaScript. How do I add functionality to the main loop, or something similar?
James19142
-4
Newbie Poster
Recommended Answers
Jump to PostHi,
you mean how to add conditional statements to a loop? For example:
…var test = 'oranges'; ['apples', 'oranges', 'mango'].forEach(function (elem, index) { // conditional statement if (elem == 'oranges') { console.log('Chosen element: ' + elem); } // default condition else { console.log('Something else.'); } });
All 3 Replies
cereal
1,524
Nearly a Senior Poster
Featured Poster
James19142
-4
Newbie Poster
AleMonteiro
238
Can I pick my title?
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.