title: How to exclude specific string from list using NodeJS
body: <p>I've use case to generate the list of strings dynamically using <strong>NodeJS</strong>, if the given string is <code>null</code> I should exclude that string from the list. <strong>For example:</strong> I've <code>productID</code>, <code>productName</code>, <code>productPrice</code> and <code>productType</code>. If <code>productID</code> is <code>null</code> then <code>productID</code> field should be excluded from the list, if <code>productName</code> is <code>null</code> then <code>productName</code> should be exclude and so on. If <code>productID</code> and <code>productName</code> are <code>null</code> then both the field should excluded from the list.</p>
  <p>I've sample code below but this is not a efficient way of doing it, can someone please suggest how can we implement this use case in a better way using NodeJS.</p>
  <pre><code>const test = async () =&gt; {
  
      console.log('generate params')
  
      var params;
  
      var productID;
      var productName = &quot;APPLE&quot;;
      var productPrice = &quot;12&quot;;
      var productType = &quot;Electronics&quot;
  
  
      if (productID == null) {
          params = {
              &quot;PRODUCT_NAME&quot;: productName,
              &quot;PRODUCT_PRICE&quot;: productPrice,
              &quot;PRODUCT_TYPE&quot;: productType
          }
      } else if (productName == null) {
          params = {
              &quot;PRODUCT_ID&quot;: productID,
              &quot;PRODUCT_PRICE&quot;: productPrice,
              &quot;PRODUCT_TYPE&quot;: productType
          }
      }
      else if (productPrice == null) {
          params = {
              &quot;PRODUCT_ID&quot;: productID,
              &quot;PRODUCT_NAME&quot;: productName,
              &quot;PRODUCT_TYPE&quot;: productType
          }
      }
      else if (productType == null) {
          params = {
              &quot;PRODUCT_ID&quot;: productID,
              &quot;PRODUCT_NAME&quot;: productName,
              &quot;PRODUCT_PRICE&quot;: productPrice,
          }
      }
      console.log(&quot;param value&quot;, params)
  }
  
  test()
  </code></pre>
  <p><strong>TypeScript</strong></p>
  <pre><code>Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ PRODUCT_ID: string[]; PRODUCT_NAME: string; PRODUCT_PRICE: string; PRODUCT_TYPE: string; }'.
    No index signature with a parameter of type 'string' was found on type '{ PRODUCT_ID: string[]; PRODUCT_NAME: string; PRODUCT_PRICE: string; PRODUCT_TYPE:
  </code></pre>
  <p><strong><code>product.ts</code></strong></p>
  <pre><code>export interface ProductInput {
    productID: Array&lt;string&gt;;
    productName: string;
    productPrice: string;
    productType: string;
    shippingDate: Date;
    DeliveryDate: Date;
  }
  
  export interface ProductOutput {
    status: string;
  }
  
  //Lambda function
  export const productDetails = async (event: ProductInput):
    Promise&lt;ProductOutput&gt; =&gt; {
  
    var PRODUCT_ID = event.productID;
    var PRODUCT_NAME = event.productName;
    var PRODUCT_PRICE = event.productPrice;
    var PRODUCT_TYPE = event.productType;
  
    const collection = { PRODUCT_ID, PRODUCT_NAME, PRODUCT_PRICE, PRODUCT_TYPE };
  
    const parameters = Object.keys(collection).reduce((acc, curr) =&gt; {
      if (collection[curr]) acc[curr] = collection[curr];
  
      return acc;
    }, {});
  
    return {
      status: 'success'
    };
  
  };
  </code></pre>