javascript - How to convert object to array -


i have json data having property attributes.data. when console.log(attributes.data) value result {"uid" : 1} want convert array. i.e {"uid" : 1} , on want convert form data uid:1. how in javascripts.

 if (attributes.type == "post") {     xmlhttp.open(attributes.type, attributes.url, true);     xmlhttp.setrequestheader('x-requested-with', 'xmlhttprequest');     xmlhttp.setrequestheader("content-type", "application/x-www-form-urlencoded; charset=utf-8");     attributes.data = json.stringify(attributes.data);     xmlhttp.send(attributes.data);   }
while debug in chrome network tab have form data {"uid" :1} want uid: 1 how convert that

if need have array values so: ['uid:1', 'key:value', ...]

then work:

var attribute = {      data: {        "uid": 1,        "key2": 'value',        "key3": 'value'        }    },    key,    mystring = '';    (key in attribute.data) {      //this line want    mystring += "&" + key + ":" + attribute.data[key];  }      //the output of fist element (there 1 now)  document.queryselector('#result').innerhtml = mystring; // "uid:1"
<div id="result"></div>

hope helps.

edit:

if want string "uid" element

var attribute = {      data: {        "uid": 1,      }    },    key,    mystring = '';    (key in attribute.data) {      //this line want    if (key === "uid") {      mystring = key + ":" + attribute.data[key]    }  }      //the output of fist element (there 1 now)  document.queryselector('#result').innerhtml = mystring; // "uid:1"
<div id="result"></div>


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -