title: Select random object from array and decrement value
body: <p>I want to know how can I randomly select an object from an array and decrement the value of <code>valid</code>.</p>
  
  <p>I have the following:</p>
  
  <pre><code>const codes = [
     {
        code: "AG1",
        valid: 20
     },
     {
        code: "AG2",
        valid: 20
     },
     {
        code: "AG3",
        valid: 20
     }
  ]
  </code></pre>
  
  <p>Now I select the object random like this</p>
  
  <pre><code>var code = codes[Math.floor(Math.random()*codes.length)];
  </code></pre>
  
  <p>After I select an object I need to decrement the object's value of valid by one</p>
  
  <p>Any idea?</p>