There seems to be an issue with the push function in my code. The problem lies in the last line of code shown below.
export enum non_searchFieldsNames {
language = 'language',
categories = 'categories',
subtitle = 'subtitle',
publishedDate = 'publishedDate',
id = 'id',
}
enum columnsEnum {
title,
authors,
language,
categories,
subtitle,
publishedDate,
}
function toArray(obj: header | contentCategories | sourceFields) {
return Object.entries(obj)
.sort((a, b) => {
return +a - +b;
})
.map(item => item[1]);
}
let sourceFieldsObject: sourceFields = {
[columnsEnum.title]: searchFieldsNames.title,
[columnsEnum.authors]: searchFieldsNames.authors,
[columnsEnum.language]: non_searchFieldsNames.language,
[columnsEnum.categories]: non_searchFieldsNames.categories,
[columnsEnum.subtitle]: non_searchFieldsNames.subtitle,
[columnsEnum.publishedDate]: non_searchFieldsNames.publishedDate,
};
const sourceFieldsArray = toArray(sourceFieldsObject).push(non_searchFieldsNames.id);
The issue arises with the latest line of code. The value returned is 7. When I simplify the code like this:
const sourceFieldsArray = toArray(sourceFieldsObject)
I get an array (minus the additional value). Separating the logic into two lines:
const sourceFieldsArray = (toArray(sourceFieldsObject));
sourceFieldsArray.push(non_searchFieldsNames.id);
Yields the desired outcome. However, I prefer a one-liner solution. What could be causing this error? I also attempted:
const sourceFieldsArray (toArray(sourceFieldsObject)).push(non_searchFieldsNames.id)
Unfortunately, this did not resolve the issue.