0

I need to convert an object on certain type, I have made a fiddle to best understand. I think I have to use maybe Object.value method ? but I'm not good at this.

https://jsfiddle.net/sebastianczech/2wfapuv4/97/

I need this at result

intensity: {1: [[54,78},[45,12]],3: [[40,50], [80,12],[99,2]], 9: [[54,21],[25,14],[25,47],[87,98],[45,45]]}
  data() {
    return {
      intensity: {
        "1": [{
          "in": "54",
          "out": "78"
        }, {
          "in": "45",
          "out": "12"
        }],
        "3": [{
            "in": "40",
            "out": "50"
          }, {
            "in": "80",
            "out": "12"
          },
          {
            "in": "99",
            "out": "2"
          }
        ],
        "9": [{
            "in": "54",
            "out": "21"
          }, {
            "in": "25",
            "out": "14"
          },
          {
            "in": "25",
            "out": "47"
          }, {
            "in": "87",
            "out": "98"
          },
          {
            "in": "45",
            "out": "45"
          }
        ]
      },
    }
  },

thanks a lot

1 Answer 1

2
 const result = Object.fromEntries(
    Object.entries(data().intensity)
      .map(([k, v]) => ([k, v.map(it => ([it.in, it.out]))]))
 );

Turn the object into an array of key-value pairs, map it to an array of key value pairs with the values being the values of the previous value objects, then turn that back into an object.

Sign up to request clarification or add additional context in comments.

1 Comment

No I can't. That's your job :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.