0

I have an Javascript Object:

 Object { [email protected]=80,  [email protected]=119,  [email protected]=240}

I want to convert this Object as an Array Like:

[{ "[email protected]"="80"}, {"[email protected]"="119"}, {"[email protected]"="240"}]

Any help would be appreciated..

4
  • strange object ... show your object in its code representation Commented Jan 7, 2016 at 9:11
  • i converted hashmap<Strnig,Integer> into JSON response using JSOn Api. Commented Jan 7, 2016 at 9:14
  • 1
    i suppose you are using Java with Hashmap,JSONArray, JSONObject classes Commented Jan 7, 2016 at 9:45
  • Yes @RomanPerekhrest Commented Jan 7, 2016 at 9:48

1 Answer 1

1

You can map properties of your object to an array (using Object.keys() and Array.prototype.map()):

var obj = {
    '[email protected]': 80,
    '[email protected]': 119,
    '[email protected]': 240
};

var result = Object.keys(obj).map(function(key) {
    var arrItem = {};
    arrItem[key] = String(obj[key]);
    return arrItem;
});

console.log(result);
Sign up to request clarification or add additional context in comments.

1 Comment

PLease check my edits above , i want separate objects

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.