There are two arrays I have created in my modules. That has been inserted below.
var a = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
var b = [{name:"Fri", value:10}, {name:"Thu", value:5}];
My requirement is I want to create another array with order of array "a". If the name is not contain in "b" array, I need to push value 0 into an new array.
Expected result,
var result = [0, 0, 0, 5, 10, 0, 0];
My Code,
const result= [];
_.map(a, (el, i) => {
if(b[i] !== undefined) {
if(el === b[i].name) {
result.push(b[i].value);
} else {
result.push(0);
}
}
});