Message from JavaScript discussions

June 2017

— Sure, you can use JSON.parse to convert JSON string to JSON object

— 

Well, to avoid misunderstanding, i have json like this :
id: id, name: name, date: date
can i convert it to array and make it like this :
date:date, id:id, name:name
?

— $.map should be enough

— I see

— You mean ["date:date", "id:id, ... ]

— Yup

— Is it possible with $.map ?

— Easier method

 var arr = [];

    for (elem in obj) {

       arr.push(elem + ":" + obj[elem]);

    }


where obj is your JS Object

Message permanent page

— Erm,

— Wait gonna write it manually

— Or this

var arr = Object.keys(obj).map(function(i) { return i + ":" + obj[i] });


where obj is your JS object

Message permanent page

— If you want without keys, just remove i + ":" from this