title: Add a dynamic variable in array into a jQuery function
body: <p>Hi here I have a array variable links. I have to add the value for <code>keywords</code> and <code>label</code>  dynamically. How do you add this? Thank you</p>
  
  <p><strong>update</strong></p>
  
  <p><strong>MyIssue</strong> I need to add(push) the value for keyword and labels dynamically in that Array for autocomplete. How to do this?</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;title&gt;jQuery UI Autocomplete - Default functionality&lt;/title&gt;
      &lt;link rel="stylesheet" href="http://jqueryui.com/themes/base/jquery.ui.all.css"&gt;
       &lt;script type="text/javascript" charset="utf-8" src="../js/cordova-1.7.0.js"&gt;&lt;/script&gt;
   &lt;script type="text/javascript" charset="utf-8" src="../js/jquery-1.7.2.js"&gt;&lt;/script&gt;
  
      &lt;script src="http://jqueryui.com/ui/jquery.ui.core.js"&gt;&lt;/script&gt;
      &lt;script src="http://jqueryui.com/ui/jquery.ui.widget.js"&gt;&lt;/script&gt;
      &lt;script src="http://jqueryui.com/ui/jquery.ui.position.js"&gt;&lt;/script&gt;
      &lt;script src="http://jqueryui.com/ui/jquery.ui.autocomplete.js"&gt;&lt;/script&gt;
      &lt;link rel="stylesheet" href="http://jqueryui.com/demos/demos.css"&gt;
      &lt;script&gt;
      $(function() {
          var links = [
          {
              keywords: ['create', 'add', 'make', 'insert', 'user'],
              label: "Create user",
              //desc: "Create a user in the system",
              //url: 'http://mysite.com/user/create/'
          },
          {
              keywords: ['create', 'add', 'make', 'insert', 'organisation'],
              label: "Create organisation",
             // desc: "Create an organisation in the system",
             // url: 'http://mysite.com/organisation/create/'
          }];
          $( "#tags" ).autocomplete({
  
               source: function(request, response) {  
               var matched = [];
  
          for (var k = 0; k &lt; links.length; k++) {
              if (checkSearchWordsMatchKeywords(request.term, links[k]['keywords'])) {
                  matched.push(links[k]);
              }
          }
          // display the filtered results
          response(matched);
  
               } 
          });
  
          function checkSearchWordsMatchKeywords(searchWords, keywords)
          {
              var searchWords = searchWords.toLowerCase();    // Lowercase the search words
              var searchWords = searchWords.split(' ');       // Break up the search into separate words
              var numOfSearchWords = searchWords.length;      // Count number of search words
              var numOfKeywords = keywords.length;            // Count the number of keywords
              var matches = [];                               // Will contain the keywords that matched the search words
  
              // For each search word look up the keywords array to see if the search word partially matches the keyword
              for (var i = 0; i &lt; numOfSearchWords; i++)
              {
                  // For each keyword
                  for (var j = 0; j &lt; numOfKeywords; j++)
                  {   
                      // Check search word is part of a keyword
                      if (keywords[j].indexOf(searchWords[i]) != -1)
                      {
                          // Found match, store match, then look for next search word
                          matches.push(keywords[j]);
                          break;
                      }
                  }
              }
              if (matches.length == numOfSearchWords)
              {
  
                  return true;
              }
              }
  
      });
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;div class="demo"&gt;
  
  &lt;div class="ui-widget"&gt;
      &lt;label for="tags"&gt;Tags: &lt;/label&gt;
      &lt;input id="tags" /&gt;
  &lt;/div&gt;
  
  &lt;/div&gt;&lt;!-- End demo --&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>