Given these two strings:
var first = 'dog,cat,lion';
var second = 'cat';
How would I do it to know if the second var is any of the words (the ones that are separated by commas) in the first vars?
See Question&Answers more detail:osGiven these two strings:
var first = 'dog,cat,lion';
var second = 'cat';
How would I do it to know if the second var is any of the words (the ones that are separated by commas) in the first vars?
See Question&Answers more detail:osYou can use Array.indexOf
:
if( first.split(',').indexOf(second) > -1 ) {
// found
}
Need IE8- support? Use a shim: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/indexOf