我的数组大小> 5000。请帮助我使用javascript中的高效代码,它可以处理上述情况(标题),因为我在JavaScript中处于新手级别。这是为了公司的任务目的。我目前在印度的学校和大学工作
以下api链接将提供印度的学校名称(JSON格式)。 https://en.wikipedia.org/w/api.php?action=query&titles=List_of_schools_in_India&prop=revisions&rvprop=content&format=json
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Autocomplete - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<script>
var intjsresult=[ "ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme",
"Nitte International School",
"National Institute of Technology",
"Nitte Meenakshi Institute of Technology",
"BMS college of Engineering",
"Rastriya Vidyalaya College of Engineering",
"Nitte School of Management",
"Massachusetts Institute of Technology"
];
function hello() {
$( "#tags" ).autocomplete({
source: intjsresult
});
}
$(hello);
</script>
</head>
<body>
<div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags">
</div>
</body>
</html>
学校/大学名称是印度理工学院 如果我提供IIT作为输入,上面应该弹出。
斯坦福大学。输入测试用例:Stanford,S U
麻省理工学院。输入麻省理工学院,马萨诸塞州,马萨
任何帮助都是非常有必要的
答案 0 :(得分:0)
Hey This is the solution That I have presented which works fine with my data set. Here is the regular expression that i am using
for (var i = 0; i < intjsresult.length; i++) {
intjsresult[i]+=" "+intjsresult[i].replace(/[^A-Z]/g, '');
};
function hello() {
$( "#tags" ).autocomplete({
source: intjsresult
});
}
For the above problem This will create a abbreviation considering the capital letters.
Thanks for your help