Thursday, February 6, 2020

Maybe you can't return out of a JavaScript forEach but you can set the counter on a for loop past the point of applicability.

This just spits up: "I can sw"

"use strict";
var startMessage = "I can swear. I can joke.";
var endMessage = "";
for (var i = 0; i < startMessage.length; i++) {
   if (startMessage[i] == "e") {
      i = startMessage.length;
   }
   else {
      endMessage = endMessage + startMessage[i];
   }
}
alert(endMessage);

 
 

Hot Jesus! This could be a good tool in your toolkit bug fix boy.

No comments:

Post a Comment