There are 2 json arrays below.
arrayA = [
{attr1: "text", attr2: true, field: "format4"},
{attr1: "text", attr2: true, field: "format2"},
{attr1: "text", attr2: true, field: "format1"},
{attr1: "text", attr2: true, field: "format3"}];
arrayB = [
{ name: 'format1', type: 'text' },
{ name: 'format2', type: 'text' },
{ name: 'format3', type: 'text' },
{ name: 'format4', type: 'text' }
];
I want to sort array B name by array A's field my goal is like this
arrayB = [
{ name: 'format4', type: 'text' },
{ name: 'format2', type: 'text' },
{ name: 'format1', type: 'text' },
{ name: 'format3', type: 'text' }
];
I thought like this but this is not my goal.
arrayB = arrayA.map((a) => {
return arrayB.filter((b) => {
return a.field === b.name
});
});
please give me a advise for accomplish my goal.