javascript - Old JSON value Changed -


i have 2 json objects columnsdata , columns when assigning columnsdata value columns both values changed.

var columnsdata = [       {id: "id"},             {id: "root_task_assignee"},       {id: "root_task_id"},       {id: "root_task_status"},       {id: "root_task_tracker"},       {id: "rt_category"},       {id: "rt_priority"},       {id: "rt_subject"}, ] var columns = []; 

using below function assigned columnsdata value columns object, , added additional fields

for(i = 0;i < columnsdata.length; i++){     columns[i] = columnsdata[i];     columns[i]["name"] = columnsdata[i]["name"] || columnsdata[i]["id"];     columns[i]["type"] = columnsdata[i]["id"]["type"] || "string"; }  

but after assigning both have same values. how old json columnsdata value changed? there other way assign values

if required keep original array pure (unchanged) should use map method of array.

var columnsdata = [   {id: "id"},         {id: "root_task_assignee"},   {id: "root_task_id"},   {id: "root_task_status"},   {id: "root_task_tracker"},   {id: "rt_category"},   {id: "rt_priority"},   {id: "rt_subject"}, ]   var columns = columnsdata.map(function(obj){      var robj = {};     robj[obj.key] = obj.value;     robj["name"] = obj.value;     .....     return robj; }); 

logic can added in map method create new array required. hope helps.


Comments