<meta name="viewport" content="width=device-width" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-typeahead/2.11.0/jquery.typeahead.min.css"></link>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/corejs-typeahead/0.11.1/typeahead.bundle.min.js"></script>
var substringMatcher = function (strs) {
return function findMatches(q, cb) {
var matches, substringRegex;
// an array that will be populated with substring matches
// regex used to determine if a string contains the substring `q`
substrRegex = new RegExp(q, 'i');
// iterate through the pool of strings and for any string that
// contains the substring `q`, add it to the `matches` array
$.each(strs, function (i, str) {
if (substrRegex.test(str)) {
"location": "Plum,Newton"
// If you like my post, I will redo this using
$.each(data, function (i, item) {
var a = data[i].location.split(",");
for (i = 0; i < a.length; i++) {
astring = astring + "\"" + a[i] + "\"" + ","
astring = astring.substring(0, astring.length - 1);
var newObj = JSON.parse(astring);
$('#the-basics .typeahead').typeahead({
source: substringMatcher(newObj)
<input class="typeahead" type="text" placeholder="Locations">