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

152
Vistas
How to copy a variable arrray from another arrray in javascripts

I have an array as below:

 const arr = [
        {
            title: 's4',
            value: '124'
        },
        {
            title: 's2',
            value: '121'
        },
        {
            title: 's3',
            value: '122'
        }
    ];

and I want to create a new another array copy from the old array same as below:

 const arrCopy = [
        {
            value: '124'
        },
        {
            value: '121'
        },
        {
            value: '122'
        }
    ];

then my code as below:

var arrCopy = [...arr,arr.value]

but it has a problem, so anyone help me, thanks.

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

0

Just as in the comment above you can use awesome Javascript functions, in this case, you would like to use the map function of your array to map every item of the array as you like.

const arrayMapped = yourArray.map(item => {
    value: item.value
  })

Here is another way using Javascript Destructuring, you just ask with properties would you like from the JS Object, in this case, you just like the value property.

  const arrayMapped = yourArray.map(( { value } ) => ( { value } ))

How Array.map works How Object Destructuring works

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can simply use Array.map, as it returns a new array with the required value.

const newArr = arr.map(element => ({ value: element.value }))
console.log(newArr);

For references : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map

about 4 years ago · Juan Pablo Isaza Denunciar

0

If you are allowed to import a library. Ramda has a lot of functions to work with arrays. For your specific question, project would do the job.

import R from "ramda";
R.project(["value"], arr)  //return equals arrCopy
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