I have a problem checking if the the word "product" is there.
add a header called "newProduct" with a value of "yes".
Right now my problem is that if the collectionName has a word of "e23product32", it doesn’t add the header
const productTags = [
"product"
];
const collectionName = 'e23product32';
const headers = {
...(productTags.some((tag) => tag.includes(collectionName)) && {
"newProduct": "yes",
}),
};
console.log(headers);
>Solution :
You’ve got your check back-to-front… "product" does not contain (include) "e23product32" but "e23product32" does contain "product"
const productTags = ["product"];
const collectionName = "e23product32";
const headers = {
...(productTags.some((tag) =>
collectionName.toLowerCase().includes(tag.toLowerCase())
) && {
newProduct: "yes",
}),
};
console.log(headers);