Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

193
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!