Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
JavaScript
oldFilesSelected[i] ="desc (sa102mla 2016-17.pdf)";
keyList="sa102mla 2016-17.pdf";
var no =$.inArray(oldFilesSelected[0], keyList);


gives me no= -1 .


---------------------------------------

What I have tried:

JavaScript
oldFilesSelected[i] ="desc (sa102mla 2016-17.pdf)";
keyList="sa102mla 2016-17.pdf";
var no =$.inArray(oldFilesSelected[0], keyList);


gives me no= -1 .
Posted
Updated 7-Dec-16 19:38pm
v2
Comments
Peter Leow 7-Dec-16 23:29pm    
What are oldFilesSelected[i] and oldFilesSelected[0]? You are using $.inArray, but where is the array? Are you looking for substring in a string?

1 solution

try this
JavaScript
var no =$.inArray(  keyList,oldFilesSelected);

refer jQuery.inArray() | jQuery API Documentation[^]
 
Share this answer
 
Comments
Abrar Kazi 12-Dec-16 4:42am    
This works only when the words are same .

Like keylist has a word : Abc and oldfilesselected has a word : Hi Abc
then it wont work it gives -1 as output
Karthik_Mahalingam 12-Dec-16 5:17am    
because it accepts input as array, not a string.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900