title: IndexedDB: Can you use an array element as a key or an index?
body: <p>Consider the following object store, with the <code>domain</code> key set as the <code>keyPath</code></p>
  
  <pre><code>var tags  = [ 
      //codes: 0 - markdown wrap tag
      //       1 - HTML wrap tag 
      //       2 - single tag
      { domain: "youtube", 
  
        bold:["*",0],
        strikethrough:["-",0],
        italic:["_",0] 
      },  
  
  
      { domain: "stackoverflow", 
  
        bold:["&lt;strong&gt;",1], 
        italic:["&lt;em&gt;",1],
        strikethrough:["&lt;del&gt;",1],
        superscript:["&lt;sup&gt;",1],
        subscript:["&lt;sub&gt;",1],
        heading1:["&lt;h1&gt;",1],
        heading2:["&lt;h2&gt;",1],
        heading3:["&lt;h3&gt;",1],
        blockquote:["&lt;blockquote&gt;",1],
        code:["&lt;code&gt;",1],
        newline:["&lt;br&gt;",2],
        horizontal:["&lt;hr&gt;",2]
      }   
  ];  
  </code></pre>
  
  <p>The above code works fine and lets me do look-ups easily and efficiently. However, there are many cases where two objects in the store are completely identical except for their <code>domain</code> attribute.</p>
  
  <p>For example, I want to add objects for all of the Stack Exchange sites to the store, and all of those objects would be equal to the one for StackOverflow. </p>
  
  <p>So, rather than create many separate objects, I want to do something like this:</p>
  
  <pre><code>var tags  = [ 
      //codes: 0 - markdown wrap tag
      //       1 - HTML wrap tag 
      //       2 - single tag
      { domain: ["youtube"], 
  
        bold:["*",0],
        strikethrough:["-",0],
        italic:["_",0] 
      },  
  
  
      { domain: ["stackoverflow","stackexchange",...], 
  
        bold:["&lt;strong&gt;",1], 
        italic:["&lt;em&gt;",1],
        strikethrough:["&lt;del&gt;",1],
        superscript:["&lt;sup&gt;",1],
        subscript:["&lt;sub&gt;",1],
        heading1:["&lt;h1&gt;",1],
        heading2:["&lt;h2&gt;",1],
        heading3:["&lt;h3&gt;",1],
        blockquote:["&lt;blockquote&gt;",1],
        code:["&lt;code&gt;",1],
        newline:["&lt;br&gt;",2],
        horizontal:["&lt;hr&gt;",2]
      }   
  ];  
  </code></pre>
  
  <p>Would it be possible to use a <code>KeyGen</code> rather than a <code>keyPath</code> and set up some kind of index that took a value and searched for it in the arrays pointed to by the <code>domain</code> key?</p>
  
  <p>Or would I have to use a cursor each time I want to do a look up?</p>
  
  <p>Some potentially helpful references are:</p>
  
  <ul>
  <li><p><a href="https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Basic_Concepts_Behind_IndexedDB" rel="nofollow">https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Basic_Concepts_Behind_IndexedDB</a></p></li>
  <li><p><a href="http://www.w3.org/TR/IndexedDB/#key-path-construct" rel="nofollow">http://www.w3.org/TR/IndexedDB/#key-path-construct</a></p></li>
  <li><p><a href="https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB" rel="nofollow">https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB</a></p></li>
  </ul>