My project involves working with two separate arrays. The first array contains normal date values:
var = [
"2022-05-01",
"2022-05-02",
...
"2022-05-30"
]
The second array consists of objects that contain specific information:
var b = [
{
"k_id": "6dcb67eb-1c8a-4239-9446-f9d8f6a68086",
"v_id": "aacc1765-a1d3-43c3-8233-beae19d258e5",
...
},
{
"k_id": "6dcb67eb-1c8a-4239-9446-f9d8f6a68086",
...
}
]
I need to transform the new array into a specific format, which should include data related to each date present in the objects. If a date from the object matches a date in the main array, an object should be created with properties based on that info. Otherwise, a blank object should be generated for that date.
Unfortunately, the current output is not as expected:
It only displays the first entry correctly while the rest appear as blank entries. Here's the code snippet I'm using:
var a = {};
dateArr = [];
for (var j = 0; j < this.date_val.length; j++) {
debugger;
var b = {}
console.log(val2.value[j]);
if (val2.value.length > 0) {
const newKey = this.date_val[j];
b[newKey] = val1.data;
a = {
value:
val2.value[j] != undefined ? val2.value[j].value : "",
value_id:
val2.value[j] != undefined
? val2.value[j].v_id
: undefined,
date:
val2.value[j] != undefined
? moment(val2.value[j].start_date).format(
"YYYY-MM-DD"
)
: this.date_val[j],
};
} else {
a = {
value: "",
value_id: undefined,
date: this.date_val[j],
};
}
dateArr.push(a);
}
this.nameArray.push({
key: val1.key,
key_val: val1.id,
date: dateArr,
});
If anyone can provide assistance or guidance on how to address this issue, it would be greatly appreciated. Thank you!