JSFiddle - React, Tailwind, and code Playground
JavaScript
var array1 = ['12345', '78273', '34784', 'AB11HB' ],
array2 = ['JJJJJ', 'ABCDEF', 'FFDDFF'],
array3 = [ 'AB11' ];
Array.prototype.containsSubString = function( text ){
for ( var i in this )
{
if ( this[i].toString().indexOf( text ) != -1 )
return i;
}
return -1;
}
Array.prototype.hasSubStringOf = function( text ){
for ( var i in this )
{
if ( text.toString().indexOf( this[i].toString() ) != -1 )
return i;
}
return -1;
}
var results = [ 'Results:' ];
var test = function( str, arr ){
if ( arr.containsSubString( str ) !== -1 )
results.push( str + ' Found in Array!' );
else
results.push( str + ' Not Found in Array!' );
};
test( 'AB11', array1 );
test( '234', array1 );
test( 'JJJ', array2 );
var test2 = function( str, arr ){
if ( arr.hasSubStringOf( str ) !== -1 )
results.push( 'Array contains substring of ' + str );
else
results.push( 'Array does not contain substring of ' + str );
};
test2( 'AB11HA', array3 );
alert( results.join('\n') );