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

194
Vistas
How to assign a modified object's values back to the object?

I want to modify one object that has a part of a value that I want in this case the letter after the dash, and I want to assign only the latter back to the target object, any ideal how to do this I want to be able to push the returned array back in to itemsObject or in to a new object ? so in final the items object should have a : 'A' , b : 'B'.

useEffect(() => {
    // context.items = {a: '1-A', b :'2-B'}
    let modify = Object.values(context.items).map((value) => {
      return value.split('-');
    });
   // itemsObject = {a : '', b : ''}
    SetLink(Object.assign(itemsObject, context.items /*or new obj that will have the new values*/));
  }, []);
  
  
  // End Result 
  
  // itemsObject = {a : 'A', b : 'B'}

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

0

You could take the keys from your original itemsObject and map each key to an array of the form [key, value], where the value is the value after the dash - from your context.items object at the particular key you're mapping. You can then wrap the mapped array of keys in a call to Object.fromEntries() which will build your new object for you:

const items = {a: '1-A', b :'2-B'}; // context.items
const itemsObject = {a: '', b: ''};

const res = Object.fromEntries(Object.keys(itemsObject).map(key => [
  key,
  items[key].split("-").pop()
]));
console.log(res); // setLink(res);

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