1

I Have this JSON object:

{
"date": "01/01/2020",
"name": "New Year",
"type": "International Holiday",
"description": "",
"type_code": "1"
}

I need to create another JSON object with this pattern:

{
   "01/01/2020":{
      "selected":true,
      "marked":true,
      "selectedColor":"green"
   }
}

For now, I just need the value in date field to be the key's name of the new object. Any sugestions?

1 Answer 1

1

Try this way

const object = {

      "date": "01/01/2020",
      "name": "New Year",
      "type": "International Holiday",
      "description": "",
      "type_code": "1"
};


const newObject = {};

newObject[object.date] = {
      "selected":true,
      "marked":true,
      "selectedColor":"green"
};

console.log(newObject); // result
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.