1

How to transform this json object array

var values =  [
       {
          "sPath": "ProjectObjectID",
          "oValue1": "00163E0306801EE288BAEC30312BAC4F",
          "keyValueOne": "",
          "keyValueTwoo": "",
          "filterType": "Service",
          "filterProfileId": 40,
          "Id": 41
       },
       {
          "sPath": "ProjectObjectID",
          "oValue1": "00163E0E46381ED79AF8F5C7687E9103",
          "keyValueOne": "",
          "keyValueTwoo": "",
          "filterType": "Service",
          "filterProfileId": 40,
          "Id": 42
       }
    ]

into this :

var values = [
  [
    "ProjectObjectID",
    "00163E0306801EE288BAEC30312BAC4F",
    "",
    "",
    "Service",
    40,
    41
  ],
  [
    "ProjectObjectID",
    "00163E0E46381ED79AF8F5C7687E9103",
    "",
    "",
    "Service",
    40,
    42
  ]
]

So I want to completely remove the object and keep it values, preferably with lo-dash for visibility but vanilla would be fine , so far I'm tyring to use Object.values(values) but I'm finding a hard way understanding the concept

1 Answer 1

3

You can map the array and use Object.values() (or lodash's _.values()) to get an array of property values.

const arr = [{"sPath":"ProjectObjectID","oValue1":"00163E0306801EE288BAEC30312BAC4F","keyValueOne":"","keyValueTwoo":"","filterType":"Service","filterProfileId":40,"Id":41},{"sPath":"ProjectObjectID","oValue1":"00163E0E46381ED79AF8F5C7687E9103","keyValueOne":"","keyValueTwoo":"","filterType":"Service","filterProfileId":40,"Id":42}]

const result = arr.map(Object.values) // lodash - _.map(arr, _.values)

console.log(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.