title: NodeJs: Compare URL Parameters & Delete Requests with array values using Express
body: <p>So, I have these Express routes for an array of objects, and made some CRUD operations, but I'm stuck at the "Delete" one.</p>
  
  <p>I want to delete an object by grabbing it's url parameter ID and check if it matches with the value of it's key. Everything seem to work except 2 things:</p>
  
  <ul>
  <li>The "text" key can be anything(doesn't matter if it's not in the array).</li>
  <li>The url ID doesn't need to match it's own "text" as long as it matches an existing one.</li>
  </ul>
  
  <p>I know I'm missing some parameters, but after googling for a while and trying a few different things, I can't seem to put my finger on it. I'm new to programming and probably explained it badly, but bear with me please.</p>
  
  <p><em>app.js</em></p>
  
  <pre><code>    var foodList = [
        {
         id:'e3ed4we23',
         text:'honey'
        },
        {
         id:'12312oi3i2',
         text:'milk'
        },
        {
         id:'1023u2kodw',
         text:'chicken'
        },
        {
         id:'213021381203',
         text:'eggs'
        }
      ];
  
      app.delete('/food-list/delete/:ingredientId', function(req, res) {
         var removeIngredient = req.body.text;
         if(!removeIngredient || removeIngredient.length == 0) {
           console.log('Cannot remove this ingredient:', removeIngredient);
           res.status(500).send({error:'Cannot remove invalid ingredient text'});
  
        }else {
           var idFound = false;
           for(var index = 0; index &lt; foodList.length; index++) {
               var foundIngredient = foodList[index];
               if(foundIngredient.id == req.params.ingredientId) {
                   console.log('Removed ingredient: ',  foundIngredient.text); 
                   foundIngredient.text = removeIngredient;
                   foodList.splice(index, 1);
                   idFound = true;
                   break;
               }
           }
            if(!idFound) {
               res.status(500).send({error:'The ID you selected is invalid, please try again'});
  
            }else {
               res.status(200).send(foodList); 
            }
  
          }
      });
  </code></pre>