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

268
Vistas
React how to setState array with another array?

I would like to set an array just with the values from another array. Should I use push for this?

well, in this case, I'm trying to get the selectedOptions array and set the selectedTags array just with selectedOptions value

but just push 1 value from the selectedOptions array!

So, someone please can spare a hint on how to map an array and get the values from it?

handleChange = (selectedOptions) => {
    this.setState({ selectedOptions });
      let options = [];

    selectedOptions.map((v) => options.push(v.value));
            this.setState((state) => ({
                selectedTags: options

            }));

        

  }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Mapping over an array

You can use the Array.map function:

const data = [
{id: 1, value: '1'},
{id: 2, value: '2'},
{id: 3, value: '3'},
{id: 4, value: '4'},
{id: 5, value: '5'},
{id: 6, value: '6'},
{id: 7, value: '7'},
]

const onlyValues = data.map(d => d.value)
console.log(onlyValues)

Adding to an array via spread

const data = [1,2,3,4,5,6,7,8,9,10]
const toBeAdded = 11

const newData = [...data, toBeAdded]
console.log(newData)

const toBeAddedArray = [11,12,13,14,15,16]
const newDataArray = [...data, ...toBeAddedArray]
console.log(newDataArray)

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