Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

171
Vistas
How to make an array unique by object key?

How to make an array unique by object key? I have dynamic checkboxes, whose id I put in the state.

In the format [checkBoxId]: e.target.value

And then I try to make a unique array from the received checked from the checkbox, but nothing comes out

[...new Map(
      myCheckboxes.map((item) => { // item {dfsd34534ftg: true} (dfsd34534ftg - id)
      const key = Object.keys(item);
      return [item[key], item];
   }),
).values()]

enter image description here

{response.map(({ id}, idx) => (
    <div key={id}>
       <Checkbox
          change={e => {
          setMyCheckboxes(prev => [
              ...prev,
              {
                [id]: e.target.checked,
              },
           ]);
          }}
          checked={myCheckboxes[idx]?.id}
       />
...
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Object.keys(item) returns Array, which you trying to use as key. You need to extract key from this array in order to make it work as you want:

 const key = Object.keys(item)[0];
 return [item[key], item];
about 4 years ago · Juan Pablo Isaza Denunciar

0

Firstly, you need to declare your checkboxes' state

const [myCheckboxes, setMyCheckboxes] = useState({}) //define a map

And then you can call setMyCheckboxes on change event like below

{response.map(({ id }, idx) => (
    <div key={id}>
       <Checkbox
          change={e => {
          setMyCheckboxes(prev => ({
              ...prev,
              [id]: e.target.checked,
           }));
          }}
          checked={myCheckboxes?.id}
       />
...
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda