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

190
Visualizações
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 Respostas
Responde à pergunta

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 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