Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何基于默认顺序对数组进行排序,以及如何基于默认数组更改特定属性_Javascript_Lodash - Fatal编程技术网

Javascript 如何基于默认顺序对数组进行排序,以及如何基于默认数组更改特定属性

Javascript 如何基于默认顺序对数组进行排序,以及如何基于默认数组更改特定属性,javascript,lodash,Javascript,Lodash,我有两个对象数组 Array 1 DefaultArray = [{type: typeA, isImportant: true, Content: ContentDefaultforA}, {type: typeB, isImportant: true, Content1: ContentDefaultforB1, Content2: ContentDefaultforB2}, {type: typeC, isImportant: false, Content: ContentDefaul

我有两个对象数组

Array 1
DefaultArray =  
[{type: typeA, isImportant: true, Content: ContentDefaultforA}, {type: typeB, isImportant: true, Content1: ContentDefaultforB1, Content2: ContentDefaultforB2}, {type: typeC, isImportant: false, Content: ContentDefaultforC}, {type: typeD, isImportant: false, Content: ContentDefaultforD}]

NewArray =
[{type: typeB, isImportant: true,, Content1: ContentDefaultforB1, isImportant: true, Content2: ContentDefaultforB2}, {type: typeA, isImportant: true, Content: ModifiedContentForA}, {type: typeD, Content: ModifiedCOntentForD}, {type: typeC, isImportant: true, Content: ModifiedCOntentForC}]
我希望使用DefaultArray中的顺序而不是NewArray中的内容来形成一个新数组。但是isImportant属性还需要返回默认数组中的内容 很像

我可以用lodash中的这个进行排序

let arrayNeeded = sortBy(NewArray, x => findIndex(DefaultArray, y => x.type === y.type))
如何使用lodash同时更改单个属性

let arrayNeeded = sortBy(NewArray, x => findIndex(DefaultArray, y => x.type === y.type))