The problem of comparing two arrays

Array a:
[
{"user_num": "75925", "MeterNo": "50005445", "BookNo": "51010"},
{"user_num": "75921", "MeterNo": "50005445", "BookNo": "51010"},
{"user_num": "7595", "MeterNo": "50005445", "BookNo": "51010"},
{"user_num": "75984", "MeterNo": "50005445", "BookNo"
{"user_num": "759020", "MeterNo": "50005445", "BookNo": "51010"},
{"user_num": "75930", "MeterNo": "50005445", "BookNo": "51010"},
{"user_num": "75911", "MeterNo": "50005445", "BookNo": "51010"},
{"user_num": "75931", "MeterNo": "50005445", "BookNo": "51010"},
{ "MeterNo": "50005445", "BookNo": "51010"},
{"user_num": "75932", "MeterNo": "50005445", "BookNo": "51010"},
{"user_num": "75913", "MeterNo": "50005445", "BookNo": "51010"}
]

array b:
[

                            {user_num:75925,name:""},
                            {user_num:75921,name:""},
                            {user_num:7595,name:""},
                            {user_num:75984,name:""},
                            {user_num:7598020,name:""},
                            {user_num:7597,name:""},
                            {user_num:75930,name:""},
                            {user_num:75911,name:""}

]

I want the effect of traversing the user_num, of array an if its value is in array b, then take out the name property of array b and add it to array a. If user_num is not in array b, add a default value name attribute (which can be set to default) to the array a.

finally, The array a will look like this:
{"user_num": "75925", "MeterNo": "50005445", "BookNo": "51010", "name": "Fan Xiaoming"},
{"user_num": "75921", "MeterNo": "50005445", "BookNo": "51010", "name": "Li Daxiao"},
{"user_num": "7595", "MeterNo": "50005445", "BookNo": "51010", "name"
{"user_num": "75984", "MeterNo": "50005445", "BookNo": "51010", "name": "Liao Bing"},
{"user_num": "759020", "MeterNo": "50005445", "BookNo": "51010", "name": "Li Gang"},
{"user_num": "75930", "MeterNo": "50005445", "BookNo": "51010", "name": "Liu Binbin"},
{" "MeterNo": "50005445", "BookNo": "51010", "name": "Sammy"},
{"user_num": "75931", "MeterNo": "50005445", "BookNo": "51010", "name": "default"},
{"user_num": "75912", "MeterNo": "50005445", "BookNo": "51010", "name": "default"},
{"user_num": "75932", "MeterNo": "50005445", "name": "default"},
{"user_num": "75913", "MeterNo": "50005445", "BookNo": "51010", "name": "default"}
]

Mar.11,2021

function assign(a, b) {
        for (let i = 0, len = a.length; i < len; iPP) {
            for (let j = 0, len = b.length; j < len; jPP) {
                if (parseInt(a[i].user_num) === parseInt(b[j].user_num)) {
                    a[i].name = b[j].name;
                    break;
                }else {
                    a[i].name= 'default';
                }
            }
        }
        return a
    }

In fact, the upstairs code is defective and it is not necessary to assign a [I] .name to a [I] .name. The value should be assigned only if the second for loop is finished if a [I] .name has no value.

function assign(a, b) {
    for (let i = 0, len = a.length; i < len; iPP) {
        for (let j = 0, len = b.length; j < len; jPP) {
            if (parseInt(a[i].user_num) === parseInt(b[j].user_num)) {
                a[i].name = b[j].name;
                break;
            }
        }
        if (a[i].name) {
            a[i].name= 'default';
        }
    }
    return a
}

array_a.forEach((itemA, index) => {
    array_b.forEach((itemB, index) => {
        if(itemA.user_num == itemB.user_num) {
            itemA.name = itemB.name
        }
    })
})

for(var v1 of a){
    v1.name="default";
    for(var v2 of b){
        if(v1.user_num==v2.user_num){
            v1.name=v2.name
        }
    }
}
console.log(a)
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ead93f-216e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ead93f-216e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?