I am facing a challenge with two JSON arrays.
$scope.arr1 = [
{ "id": 1, "first_name": "Philip", "last_name": "Kim", "email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1e6e7577732e5e737b7a777f78776c7b307d7173">[email protected]</a>", "country": "Indonesia", "ip_address": "29.107.35.8" },
{ "id": 2, "first_name": "Judith", "last_name": "Austin", "email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="543e352127203d3a651439352425213127207a373b39">[email protected]</a>", "country": "China", "ip_address": "173.65.94.30" },
{ "id": 3, "first_name": "Julie", "last_name": "Wells", "email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="117b66747d7d622351787d7d787f7e78623f747564">[email protected]</a>", "country": "Finland", "ip_address": "9.100.80.145" },
{ "id": 4, "first_name": "Gloria", "last_name": "Greene", "email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="99fefeebfcfcf7fcaad9fbf5f6feeab7faf6f4">[email protected]</a>", "country": "Indonesia", "ip_address": "69.115.85.157" },
{ "id": 5, "first_name": "Andrea", "last_name": "Greene", "email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c6a7a1b4a3a3a8a3f286a0a2a7e8a1a9b0">[email protected]</a>", "country": "Russia", "ip_address": "128.72.13.52" }]
$scope.arr2=[];
I aim to transfer elements from arr1 to arr2 one by one based on specific conditions.
var object;
var temp = {};
for (var i in $scope.arr1) {
object = $scope.arr1[i];
for (var property in object) {
temp2 = object.id + '_' + property;
if ($scope.someOtherData.indexOf("unhighlighted") != -1) {
temp[property] = "";
}
else {
temp[property] = object[property];
}
}
$scope.arr2.push(temp);
}
My primary inquiry is regarding the issue I encounter when pushing values from temp to arr2. Subsequent pushes result in all elements in arr2 taking the last temp value. How can this be resolved?
Secondly, I have noticed the spontaneous occurrence of adding $$hashKey attribute to arr1. Is there a way to prevent this from happening?