jquery: determine if a string contains characters of an array -


i'm having following code:

var specialchars = [246,214,228,196,252,220,223]; // holds german umlauts + ß var foo = "abcdefä41hl"; 

what's best practise detecting if foo contains character's ascii-code array? in case return true contains "ä" (ascii code 228).

thanks

you can detect by,

var specialchars = [246,214,228,196,252,220,223]; var foo = "abcdefä41hl"; var isexist = !!([...foo].find(itm => specialchars.includes(itm.charcodeat())));  console.log(isexist); // true 

or use array.prototype.some instead of find suggested in comment,

var isexist = [...foo].some(itm => specialchars.includes(itm.charcodeat())); 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -