Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140734

How to take particular key value pairs from json array

$
0
0

I have a large amount of data in JSON array format. A shorter version of which is as shown below

[{"Item": "Item1", "Unit CP": 100, "Unit SP": 150, "Quantity": 1, "TotalSP": 150},
{"Item": "Item2", "Unit CP": 50, "Unit SP": 70, "Quantity": 7, "TotalSP": 490},
{"Item": "Item3", "Unit CP": 1000, "Unit SP": 900, "Quantity": 1, "TotalSP": 900},
{"Item": "Item4", "Unit CP": 200, "Unit SP": 500, "Quantity": 2, "TotalSP": 1000},
{"Item": "Item5", "Unit CP": 300, "Unit SP": 311, "Quantity": 3, "TotalSP": 933},
{"Item": "Item6", "Unit CP": 750, "Unit SP": 755, "Quantity": 2, "TotalSP": 1510}]

i want to get a JSON array of objects with keys "Item" and "Unit SP" only i.e

[{"Item": "Item1", "Unit SP": 150},
{"Item": "Item2", "Unit SP": 70},
{"Item": "Item3", "Unit SP": 900},
{"Item": "Item4", "Unit SP": 500},
{"Item": "Item5", "Unit SP": 311},
{"Item": "Item6", "Unit SP": 755}]

Is there a simpler way to do so in javascript without parsing through the whole array? Thanks in advance


Viewing all articles
Browse latest Browse all 140734

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>