Just to illustrate what I want to do I’ll pase this sample code for example:
<html>
<head>
</head>
<body>
<script type="text/javascript">
function oc(a)
{
var o = {};
for(var i=0;i<a.length;i++)
{
o[a[i]]='';
}
return o;
}
if ( "Island" in oc(["Hello","Hello World","Have","Island"]) )
{
document.write("Yes");
}
</script>
</body>
</html>
In this case I get Yes on my page, but if I change the condition like:
if ( “Isl” in oc([“Hello”,”Hello World”,”Have”,”Island”]) )
the function doesn’t find match. What is the best way to perform such kind of check which will return true even if only part of the string match?
Thanks
Leron
Use
.indexOf():indexOf()returns the position where the value is found. If there is no match it returns-1so we need to check if the result is greater or equal to0.