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,315
  • 3
  • 28
  • 42
Atlas91
  • 5,754
  • 17
  • 69
  • 141

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,441
  • 22
  • 31