Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I check if specific words contain in JS

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading