Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

JSON Array:

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

need to convert it to:

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

Any quickest help will be highly apprecaited.

share|improve this question
    
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. –  Niet the Dark Absol 15 hours ago
    
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? –  cookie monster 15 hours ago
    
add comment

put on hold as unclear what you're asking by cookie monster, Felix Kling, OneKitten, KatieK, iCodez 13 hours ago

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers

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).

share|improve this answer
    
Thank you. This helps. –  user3421622 4 hours ago
add comment

Try this:

var convertedArray = JSON.parse(jsonArray);
share|improve this answer
    
This doesn't appear to perform what was specified in the question. It just parses it, but it doesn't transform the object into an array of strings. –  OneKitten 14 hours ago
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.