0

I have set of object values, i need them to be change to array .

 var data =[
  {
    "project": "Sciera Internal Application",
    "hours": {
      "DATA SCIENCE": 3270,
      "DEVELOPMENT": 2895,
      "QUALITY ENGINEERING": 780,
      "OPERATION": 33175,
      "MARKET": 3935,
      "DATA": 15750
    }
  },
  {
    "project": "RealWatch",
    "hours": {
      "OPERATION": 2490,
      "DATA SCIENCE": 810,
      "QUALITY ENGINEERING": 26045,
      "DATA ": 21340
    }
  },
 ]

i need them to be changed like array of array and colon to be replace by comma.

 data: [ ["DATA SCIENCE",3270],["DEVELOPMENT",7.36],["QUALITY ENGINEERING",7.02],["OPERATION",5.11],["MARKET",6.1],["DATA",2.95]]

1 Answer 1

1

One-liner solution: Merge all data.hours into one object, then use Object.entries() to get the key value pair as a comma separated array.

var data = [{
    "project": "Sciera Internal Application",
    "hours": {
      "DATA SCIENCE": 3270,
      "DEVELOPMENT": 2895,
      "QUALITY ENGINEERING": 780,
      "OPERATION": 33175,
      "MARKET": 3935,
      "DATA": 15750
    }
  },
  {
    "project": "RealWatch",
    "hours": {
      "OPERATION": 2490,
      "DATA SCIENCE": 810,
      "QUALITY ENGINEERING": 26045,
      "DATA": 21340
    }
  },
]

const results = Object.entries(Object.assign({}, ...data.map(datum => datum.hours)));
console.log(results)

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.