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

95
Views
Editing/Adding value in object of objects

Main problem is that key format is not supported for selecting. I do have automatically generated object list with unique keys. Index and key is known. I do need to add value to custom_property object or edit if it already exists.

Code snapshot:

let initialValue = {
  "126ccbb5-1a89-40a9-9393-6849a2f502bc": {
  "uuid": "126ccbb5-1a89-40a9-9393-6849a2f502bc",
  "order": 0,
  "custom_properties": {
  },
  },
  "82945a12-ffcb-4dba-aced-e201fa9a531e": {
  "uuid": "82945a12-ffcb-4dba-aced-e201fa9a531e",
  "order": 1,
  "custom_properties": {
  },
  }
  }

I do have these values that I want to insert/update on the custom_property array

const index = 0;
const name = "some_title"
const value = {value: 1, label: "some label"}

How result should look like:

let initialValue = {
      "126ccbb5-1a89-40a9-9393-6849a2f502bc": {
      "uuid": "126ccbb5-1a89-40a9-9393-6849a2f502bc",
      "order": 0,
      "custom_properties": {
       "some_title" : {value: 1, label: "some label"}
      },
      },
      "82945a12-ffcb-4dba-aced-e201fa9a531e": {
      "uuid": "82945a12-ffcb-4dba-aced-e201fa9a531e",
      "order": 1,
      "custom_properties": {
      },
      }
      }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

you can do something like this

const update = (data, index, key, value) => 
Object.fromEntries(Object.entries(data).map(([k, v], i) => i === index? [k, {...v, custom_properties: Object.assign({}, v.custom_properties, {[key]: value})}]:[k,v]))


let initialValue = {
  "126ccbb5-1a89-40a9-9393-6849a2f502bc": {
    "uuid": "126ccbb5-1a89-40a9-9393-6849a2f502bc",
    "order": 0,
    "custom_properties": {},
  },
  "82945a12-ffcb-4dba-aced-e201fa9a531e": {
    "uuid": "82945a12-ffcb-4dba-aced-e201fa9a531e",
    "order": 1,
    "custom_properties": {},
  }
}

const newValue = update(initialValue, 0, 'newKey', 'newValue')

console.log(newValue)

about 4 years ago · Juan Pablo Isaza Report

0

You can try using Object.values() and get the array of items and then pass down the index like,

Object.values(data)[index]

Then assign the dynamic key-value to the custom_properties like,

item.custom_properties = {
  [name]: value,
};

Working Snippet:

  let initialValue = {
    '126ccbb5-1a89-40a9-9393-6849a2f502bc': {
      uuid: '126ccbb5-1a89-40a9-9393-6849a2f502bc',
      order: 0,
      custom_properties: {},
    },
    '82945a12-ffcb-4dba-aced-e201fa9a531e': {
      uuid: '82945a12-ffcb-4dba-aced-e201fa9a531e',
      order: 1,
      custom_properties: {},
    },
  };

  const index = 0;
  const name = 'some_title';
  const value = { value: 1, label: 'some label' };

  const getUpdatedResult = (data) => {
    const item = Object.values(data)[index];

    if (item) {
      item.custom_properties = {
        [name]: value,
      };
    }

    return data;
  };

  console.log(getUpdatedResult(initialValue));

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!