Javascript If array element contains a period -
i want search through array i've made string, if has period @ end of element, randomly (50% chance) add "arr!" before next sentence. problem is, don't quite know how check if there period @ end of given array element. i'm guessing regular expressions best, i'm terrible them... able provide insight??
var things = output2.value.split(" "); (var = 0; < things.length; i++) {   things[i] += " ";   if (things[i]==".") {     var randnumb = math.floor((math.random() * 2) + 1)     if (randnumb == 1) {       things[i] += " arr!"     };   }  }; 
regex inefficient.
var stringtocheck = 'something'; var period = '.';  //check if string ends period (.) if (stringtocheck.indexof(period, this.length - period.length) !== -1) {     //your code here } 
Comments
Post a Comment