napi15
napi15

Reputation: 2402

transform an array of json objects to array

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

Upvotes: 1

Views: 33

Answers (1)

Ori Drori
Ori Drori

Reputation: 193077

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)

Upvotes: 3

Related Questions