title: Is it possible to store data in function to an object literal by passing argument to a function?
body: <p>I added my html and js snippet however it still not completed. Sorry if the code is a bit messy this is my first attempt for me to build something like this on my own.</p>
  
  <p>`</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var selectBread = document.querySelectorAll(".bread-select");
  var sauceSelect = document.querySelectorAll(".sauces-select");
  var checkBoxes = document.getElementsByTagName("input");
  var orderModal = document.getElementById("order-modal");
  let chosenItem;
  let chosenItemPrice;
  var ingredients = [];
  var ingredientsPrice = [];
  let selectedItem;
  var sideDishes = [];
  var drink = [];
  var toasted;
  var currentSandwich = {};
  var breadAndPrice = [
    ["baguette", 0.8],
    ["burger bun", 0.8],
    ["ciabatta", 0.9],
    ["focaccia", 1.5],
    ["ftira", 0.8],
    ["olive bread", 1.3],
    ["rye bread", 1.3],
    ["sliced bread", 0.9],
    ["tortilla", 1.6],
    ["wheat bread", 0.9],
    ["whole grain bread", 1.2]
  ];
  var sauceAndPrice = [
    ["chili sauce", 0.25],
    ["garlic and olive oil", 0.35],
    ["ketchup", 0.15],
    ["mayonnaisee", 0.15],
    ["garlic basil mayo", 0.45],
    ["mustard", 0.25]
  ];
  
  function getBreadInfo(el, currentOption) {
    for (var i = 0; i &lt; el.length; i++) {
      //add event listener to all bread select menu options
      el[i].addEventListener("change", function() {
        selectedItem = event.target.value; //current selected item
        getArrIndex(currentOption, selectedItem);
        if (event.target.name === "bread-select") {
          currentSandwich.breadType = chosenItem;
          currentSandwich.breadPrice = chosenItemPrice;
        } else if (event.target.name === "sauce-select") {
          currentSandwich.sauce = chosenItem;
          currentSandwich.saucePrice = chosenItemPrice;
        } else if (event.target.name === "side-dishes-select") {
          currentSandwich.sideDish = chosenItem;
          currentSandwich.sideDishPrice = chosenItemPrice;
        } else if (event.target.name === "drinks-select") {
          currentSandwich.drinkSelect = chosenItem;
          currentSandwich.drinkPrice = chosenItemPrice;
        } else if (event.target.name === "toasted-select") {
          currentSandwich.toasted = chosenItem;
        }
      });
    }
  }
  
  function getArrIndex(arr, val) {
    // val is the selected item
    for (var i = 0; i &lt; arr.length; i++) {
      //iterate through the current choosen array
      if (arr[i][0] === val) {
        // when selected item is found in the array
        chosenItem = arr[i][0]; // store the item in choosenItem value
        chosenItemPrice = arr[i][1]; // store the item price in choosenItem value
      }
    }
  }
  getBreadInfo(selectBread, breadAndPrice);
  getBreadInfo(sauceSelect, sauceAndPrice);
  //get the index of the selected item from the bread and price array
  
  function getIngredientsInfo() {
    for (var i = 0; i &lt; checkBoxes.length; i++) {
      //loop check boxes
      checkBoxes[i].addEventListener("change", function() {
        //add event listener to check boxes
        if (event.target.checked) {
          //check if check boxes are checked
          ingredients.push(event.target.name); //push the name of ingredient to ingredients array
          ingredientsPrice.push(event.target.value); //get the price of the item checked from value attr and push it to ingredientsPrice array
        } else if (event.target.checked === false) {
          var index = ingredients.indexOf(event.target.name);
          ingredients.splice(index, 1);
          ingredientsPrice.splice(index, 1);
        }
      });
    }
  }
  getIngredientsInfo();</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;section class="order-section"&gt;
    &lt;h2 class="selection-header"&gt;Choose your...&lt;/h2&gt;
    &lt;div class="select-container"&gt;
  
      &lt;select class="bread-select" name="bread-select"&gt;
        &lt;option selected disabled&gt;Bread Type&lt;/option&gt;
        &lt;option value="baguette"&gt;Baguette&lt;/option&gt;
        &lt;option value="burger bun"&gt;Burger Bun&lt;/option&gt;
        &lt;option value="ciabatta"&gt;Ciabatta&lt;/option&gt;
        &lt;option value="focaccia"&gt;Focaccia&lt;/option&gt;
        &lt;option value="ftira"&gt;Ftira&lt;/option&gt;
        &lt;option value="olive bread"&gt;Olive Bread&lt;/option&gt;
        &lt;option value="rye bread"&gt;Rye Bread&lt;/option&gt;
        &lt;option value="sliced bread"&gt;Sliced Bread&lt;/option&gt;
        &lt;option value="tortilla"&gt;Tortilla&lt;/option&gt;
        &lt;option value="wheat bread"&gt;Wheat Bread&lt;/option&gt;
        &lt;option value="whole grain bread"&gt;Whole Grain Bread&lt;/option&gt;
      &lt;/select&gt;
  
  
      &lt;select class="sauces-select" name="sauce-select"&gt;
        &lt;option selected disabled&gt;Sauces&lt;/option&gt;
        &lt;option value="chili sauce"&gt;Chili Sauce&lt;/option&gt;
        &lt;option value="garlic and olive oil"&gt;Garlic and Olive Oil&lt;/option&gt;
        &lt;option value="ketchup"&gt;Ketchup&lt;/option&gt;
        &lt;option value="mayonnaise"&gt;Mayonnaise&lt;/option&gt;
        &lt;option value="garlic basil mayo"&gt;Garlic Basil Mayo&lt;/option&gt;
        &lt;option value="mustard"&gt;Mustard&lt;/option&gt;
      &lt;/select&gt;
  
      &lt;select class="side-dishes-select" name="side-dishes-select"&gt;
        &lt;option selected disabled&gt;Side Dishes&lt;/option&gt;
        &lt;option value="coleslaw"&gt;Coleslaw&lt;/option&gt;
        &lt;option value="curly fries"&gt;Curly Fries&lt;/option&gt;
        &lt;option value="mixed salad"&gt;Mixed Salad&lt;/option&gt;
        &lt;option value="potato wedges"&gt;Potato Wedges&lt;/option&gt;
        &lt;option value="potatoes salad"&gt;Potatoes Salad&lt;/option&gt;
        &lt;option value="sliced Potatoes fries"&gt;Sliced Potatoes Fries&lt;/option&gt;
        &lt;option value="sweet potatoes fries"&gt;Sweet Potatoes Fries&lt;/option&gt;
      &lt;/select&gt;
  
      &lt;select class="drinks-select" name="drinks-select"&gt;
        &lt;option selected disabled&gt;Drinks&lt;/option&gt;
        &lt;option value="Still Water"&gt;Still Water&lt;/option&gt;
        &lt;option value="Fizzy Water"&gt;Fizzy Water&lt;/option&gt;
        &lt;option value="coca cola"&gt;Coca Cola&lt;/option&gt;
        &lt;option value="sprite"&gt;Sprite&lt;/option&gt;
        &lt;option value="fanta"&gt;Fanta&lt;/option&gt;
        &lt;option value="kinnie"&gt;Kinnie&lt;/option&gt;
        &lt;option value="cisk"&gt;Cisk&lt;/option&gt;
      &lt;/select&gt;
  
      &lt;select class="toasted-select" name="toasted-select"&gt;
        &lt;option selected disabled&gt;Toasted&lt;/option&gt;
        &lt;option value="yes"&gt;Yes&lt;/option&gt;
        &lt;option value="no"&gt;No&lt;/option&gt;
      &lt;/select&gt;
    &lt;/div&gt;
  
  &lt;/section&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>`I have a function which I am using to get data from select menus and I would like to save the data to an object by passing it as an argument. At the moment the only solution I found is to use if statements but it look bad. Any help to refactor this please? </p>
  
  <pre><code>      if (event.target.name === "bread-select") {
      currentSandwich.breadType = chosenItem;
      currentSandwich.breadPrice = chosenItemPrice;
    } else if (event.target.name === "sauce-select") {
      currentSandwich.sauce = chosenItem;
      currentSandwich.saucePrice = chosenItemPrice;
    } else if (event.target.name === "side-dishes-select") {
      currentSandwich.sideDish = chosenItem;
      currentSandwich.sideDishPrice = chosenItemPrice;
    } else if (event.target.name === "drinks-select") {
      currentSandwich.drinkSelect = chosenItem;
      currentSandwich.drinkPrice = chosenItemPrice;
    } else if (event.target.name === "toasted-select") {
      currentSandwich.toasted = chosenItem;
    }
  </code></pre>