Access and change 2d Json Array, Javascript -


i'm trying access , change data receive json api call.

the format of call this:

{   "count": 391,   "value": [     {       "id": "id1",       "name": "name1",       "url": "url1",       "project": {         "id": "projid",         "name": "bt-git",         "url": "otherurl",         "state": "wellformed"       },       "defaultbranch": "master",       "remoteurl": "remote"     },      {       "id": "id2",       "name": "name2",       "url": "url2",       "project": {         "id": "projid",         "name": "bt-git",         "url": "otherurl",         "state": "wellformed"       },       "defaultbranch": "master",       "remoteurl": "remote"     },... 

and want add entry each "value", such have:

       {           "id": "id1",           "name": "name1",           "url": "url1",           "project": {             "id": "projid",             "name": "bt-git",             "url": "otherurl",             "state": "wellformed"           },           "defaultbranch": "master",           "remoteurl": "remote"           "date": "date" <---------         } 

i've tried:

$.each(data, function (idx) {               data.value[idx].currentdate = new date().tojson().slice(0, 16);           }) 

and:

$.each(data, function (idx) {               data[1][idx].currentdate = new date().tojson().slice(0, 16);           }) 

any ideas on how remedy problem?

much thanks.

you can existing code need tweaking,

var data = {     "count": 391,     "value": [{         "id": "id1",         "name": "name1",         "url": "url1",         "project": {             "id": "projid",             "name": "bt-git",             "url": "otherurl",             "state": "wellformed"         },         "defaultbranch": "master",         "remoteurl": "remote"     }, {         "id": "id2",         "name": "name2",         "url": "url2",         "project": {             "id": "projid",             "name": "bt-git",             "url": "otherurl",             "state": "wellformed"         },         "defaultbranch": "master",         "remoteurl": "remote"     }] };  $.each(data.value, function (index,data) {               data.currentdate = new date().tojson().slice(0, 16);           }); console.log(data); 

see demo : https://jsfiddle.net/mj3vu6s6/4/


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -