I need to clone a data from JSON a key of array, and then edit the newly added key.
Here's the full code i used :
var test_arr = [{'name' : 'data','item':'data2'},{'name' : 'helw','item':'data3'}];
var test_arr1 = test_arr[1];
test_arr.push(test_arr1);
index = 2;
var datas = test_arr[index];
datas.name = 'janjan';
console.log(test_arr);
From the code above, i copied test_arr[1] and pushed it into the test_arr, creating a new index,
I successfully added a new index on test_arr (test_arr[2]) but when i edit test_arr[2], it also edits test_arr[1].
[
{ name: 'data', var2: 'data2' },
{ name: 'janjan', var3: 'data3' },
{ name: 'janjan', var3: 'data3' }
]
Is there a way to only edit test_arr[2] only?