Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

88
Visualizações
Unique rows Indexeddb indexed array

I have a store in IndexedDB where the Key path is for property Id and I also have an indexed array called IndexedWords

[{ Id: 1, IndexedWords: ['Foo', 'bar'] }, { Id: 2, IndexedWords: [] } }

I am trying to find all empty rows in the store and this by finding Id of all with value in IndexedWords + all Id of the store and intersecting those arrays. The idea works but the problem is that I am receiving the Ids for the IndexedWords x number of times where x matches the number of entries in IndexedWords and when I have 5000 rows and each row have 100+ words, the array is getting large and harder to work with. Is there any way of returning only distinct Ids from IndexedDB in the query? Current code below

var trans = db.transaction(storeName, IDBTransaction.READ_ONLY);
var index = trans.objectStore(storeName).index("IndexedWords");
var getAllRequest = index.getAllKeys();
getAllRequest.onsuccess = function (evt) {
    items = evt.target.result;
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

If I understand your question, you could try creating a multiple entry index on IndexedWords and then iterating over the unique keys of the index.

about 4 years ago · Juan Pablo Isaza Relatório

0

I hope this helps, without the overhead of the IndexedDB API, since I was not able to get your IndexedDB sample code working.

Iterate over the words and create a new object containing a word as the key, with an array of Ids as the value if the word is in the IndexedWords for the item.

Create an empty object and some sample data

let index = [{ Id: 1, IndexedWords: ['Foo', 'bar'] }, { Id: 2, IndexedWords: ['blue', 'cat', 'mouse'] }, {Id: 242, IndexedWords: ['salmon', 'blue', 'bar']} ];
let wordz = {};

Create a flat array of all the unique words from the sample data, and remove the duplicates from the array of all of the words to get a list of distinct words.

let allWords = index.map((z) => (z.IndexedWords)).flat()
allWords = [...new Set(allWords)]

Iterate over each unique word and create a new object with the word as the key, with an array of Ids as the value

allWords.forEach( (word) => {
    // create an empty array for the new wordz[word]
    wordz[word] = []

    // push the item Id onto wordz[word] //
    index.forEach((item) => {
        if(item.IndexedWords.indexOf(word)>=0) {
            wordz[word].push(item.Id);
            }
    })
})



console.log(wordz)

Foo: [1]
bar: (2) [1, 242]
blue: (2) [2, 242]
cat: [2]
mouse: [2]
salmon: [242]
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda