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

141
Visualizações
using electron-store with ip as key

Hy,

i try to use electron-store to persist values by ip as key. Using the code:

store.set('users.' + ip, 'foo')

So i want to achieve following object:

{users: [{"192.186.0.0": "foo"},{"192.186.0.1": "bar"}]}

but what i got is

"192": { "168": { "192": { "151": "Foo", "134": "Bar",.....

So is there a way to use ips?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

So what you want is essentially an array of objects, where the objects key is the ip address. In this case though I would rather recommend using an array of arrays because it makes working with the data a bit easier.

So first we create a new Map, which holds our users ip and name:

let map=new Map();
map.set('192.186.0.0', 'foo');
map.set('192.186.0.1', 'bar');

To store this Map using electron-store, we need to pack it into an array and populate the users key.

store.set('users', Array.from(map.entries(map)));

If we want to read out or modify values from the users key, we need to convert the array back to a map.

Let's look at an example - we want to modify 192.186.0.0 to say title instead of foo:

let map=new Map(store.get('users'));
map.set('192.186.0.0', 'title');
store.set('users', Array.from(map.entries(map)));
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