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

98
Views
How to arrange values of Object with uniqueID

I have an object with details - name, email, contact with unique ID

{
 email_IcWDC6iyNzsQe9sPss4Yy: "xyz@gmail.com"
 email_QVXeOX1vijCtpx8mdD662: "abc@gmail.com"
 mobile_IcWDC6iyNzsQe9sPss4Yy: "223"
 mobile_QVXeOX1vijCtpx8mdD662: "122"
 name_IcWDC6iyNzsQe9sPss4Yy: "mp"
 name_QVXeOX1vijCtpx8mdD662: "pp"
}

for example: name_QVXeOX1vijCtpx8mdD662 this contains name_UniqueID but remains same for one set of form for name, email, mobile. These values are taken from as many forms generated in the frontend, form has unique Id and that has been pass to their fields, so how can I make a new collection of objects containing a name, email, mobile for a particular unique id as given.

example:

[
{
 id: "IcWDC6iyNzsQe9sPss4Yy"
 name: "mp",
 email: "",
 mobile_no: "",
},
{
 id: "QVXeOX1vijCtpx8mdD662"
 name: "pp",
 email: "",
 mobile_no: "",
},
]

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

One way of doing it:

const d = {
 email_IcWDC6iyNzsQe9sPss4Yy: "xyz@gmail.com",
 email_QVXeOX1vijCtpx8mdD662: "abc@gmail.com",
 mobile_IcWDC6iyNzsQe9sPss4Yy: "223",
 mobile_QVXeOX1vijCtpx8mdD662: "122",
 name_IcWDC6iyNzsQe9sPss4Yy: "mp",
 name_QVXeOX1vijCtpx8mdD662: "pp"
};

const result = Object.values(
  Object.entries(d).reduce((acc, [k, v]) => {
    const [field, id] = k.split("_", 2);
    if (!acc[id]) acc[id] = {id};
    acc[id][field] = v;
    return acc;
  }, {})
);

console.log(result);

about 4 years ago · Juan Pablo Isaza Report

0

Not very efficient, but could be a sol:

const parentObj = {
         email_IcWDC6iyNzsQe9sPss4Yy: "xyz@gmail.com",
         email_QVXeOX1vijCtpx8mdD662: "abc@gmail.com",
         mobile_IcWDC6iyNzsQe9sPss4Yy: "223",
         mobile_QVXeOX1vijCtpx8mdD662: "122",
         name_IcWDC6iyNzsQe9sPss4Yy: "mp",
         name_QVXeOX1vijCtpx8mdD662: "pp"
    };
let resultArr = [];
for (const key in parentObj) {
    const template = {
        id:"",
        name:"",
        email:"",
        mobile:"",
    };
    let [prop,uid] = key.split("_");
    if(!resultArr[uid]){
        template.id = uid;
        resultArr[uid] = template;
    }
    resultArr[uid][prop] = parentObj[key];
}
console.log(resultArr);
about 4 years ago · Juan Pablo Isaza Report

0

you can use dependecies called UUID or NanoId from NPM. this dependencies can be used for an unique ID. to apply it use:

const idVar = uuidv4() || nanoid();
const obj = {
 ['id_' + idVar]: 'abcdefg2312',
 ['name_' + idVar]: "pp",
 ['email_' + idVar]: "",
 ['mobileNo_' + idVar]: "",
}
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!