-4

JSON Array:

[ { sw: 'NODE.JS' }, { sw: 'Heroku Toolbelt' } ]

need to convert it to:

['NODE.JS','Heroku Toolbelt']. 

Any quickest help will be highly apprecaited.

3
  • JSON is a string. "JSON Array" is not a thing. What you have is an array of objects, that you want to convert to an array based on a property of those objects. Commented Apr 15, 2014 at 15:35
  • What's the problem? You don't know how to use a for loop? or you don't know how to add items to a new Array? Commented Apr 15, 2014 at 15:40
  • possible duplicate of javascript array of objects, extract value of a property as array Commented Apr 15, 2014 at 15:44

1 Answer 1

1

I'd use Array.prototype.map:

var new_array = arr.map(function(e) {
    return e.sw;
});

Don't forget to get the actual JavaScript array from the JSON string with JSON.parse (as an example).

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.