0

I've got a json like this:

"values": [
    {"name": "name1"},
    {"name": "name2"},
    {"name": "name3"}
]

and but now i need convert it into this:

values: ["name1", "name2", "name3"];

In angularjs (or some function in javascript). Is it possible?

Alex Andrei
  • 7,137
  • 3
  • 26
  • 41
Atlas91
  • 5,570
  • 15
  • 60
  • 126

1 Answers1

3

You're looking for a simple map function:

json.values = json.values.map(function(valObj){ return valObj.name; });

(Obviously, for readability, you may want to rename valObj to something more descriptive of your Objects)

DRobinson
  • 4,391
  • 20
  • 31