0

I'm trying to iterate through an array and have multiple cases for what the object in the array could be...

   for (var i = 0; i < firstWords.length; i++) 
    {
        var keyword = firstWords[i];
        var orderNumber = 0;
        var type = [];
        switch(keyword) {
            case 'const':
                console.log("Constant Defined");
            case 'function': 
                console.log('Function Defined');
            default: 
                console.log('Misc');
        }
    }

It does go through the array and log a response based on what the object is, but the order in which it logs it is weird. I input this as a test:

const
const
const
function
misc

And it logs this:

Constant Defined
Function Defined
Misc
Constant Defined
Function Defined
Misc
Constant Defined
Function Defined
Misc
Function Defined
(2)Misc

What I want it to do is log each one in order. So in this case, it should say "Constant defined" 3 times first, and then "Function defined" and "Misc" How do I get it to do that? Thanks.

Apple Pie
  • 9
  • 1
  • 7

0 Answers0