title: What is the purpose of -1 at the end of an if statement in Javascript
body: <p>Having the following code which gets as input a JSON of this format:</p>
  <pre><code>{
    &quot;143334&quot;: [&quot;VW&quot;, &quot;Golf&quot;, &quot;Diesel or Gas&quot;, &quot;Affordable&quot;, &quot;Blue, red or white&quot;],
    &quot;344389&quot;: [&quot;VW&quot;, &quot;Passat&quot;, &quot;Diesel or Gas&quot;, &quot;More expensive&quot;],
    &quot;484612&quot;: [&quot;Audi&quot;, &quot;A8&quot;, &quot;Diesel&quot;, &quot;Premium&quot;],
    &quot;234234&quot;: [&quot;Renault&quot;, &quot;Megane&quot;, &quot;not too much info&quot;]
  }
  </code></pre>
  <p>and returns it grouped by brand and sorts it alphabetically by brand and model:</p>
  <pre><code>[
    {
      &quot;brand&quot;: &quot;Audi&quot;,
      &quot;models&quot;: [
        {
          &quot;model&quot;: &quot;A8&quot;,
          &quot;id&quot;: &quot;484612&quot;,
          &quot;characteristics&quot;: [&quot;Diesel&quot;, &quot;Premium&quot;]
        }
      ]
    },
    {
      &quot;brand&quot;: &quot;Renault&quot;,
      &quot;models&quot;: [
        {
          &quot;model&quot;: &quot;Megane&quot;,
          &quot;id&quot;: &quot;234234&quot;,
          &quot;characteristics&quot;: [&quot;not too much info&quot;]
        }
      ]
    },
    {
      &quot;brand&quot;: &quot;VW&quot;,
      &quot;models&quot;: [
        {
          &quot;model&quot;: &quot;Golf&quot;,
          &quot;id&quot;: &quot;143334&quot;,
          &quot;characteristics&quot;: [&quot;Diesel or Gas&quot;, &quot;Affordable&quot;, &quot;Blue, red or white&quot;]
        },
        {
          &quot;model&quot;: &quot;Passat&quot;,
          &quot;id&quot;: &quot;344389&quot;,
          &quot;characteristics&quot;: [&quot;Diesel or Gas&quot;, &quot;More expensive&quot;]
        }
      ]
    }
  ]
  </code></pre>
  <p>The implementation works well, it was answered in a different question:</p>
  <pre><code>function doMagic(json) {
    let res = [];
    let arr = JSON.parse(json)
    Object.keys(arr).forEach(k =&gt; {
      let tempIndex = res.findIndex(r =&gt; r.brand === arr[k][0])
      if(-1 === tempIndex) { // if the brand isn't in the array yet
        tempIndex = res.push({
          brand:arr[k][0],
          models:[]
        })-1
      }
      res[tempIndex].models.push({
          &quot;model&quot;: arr[k][1],
          &quot;id&quot;: k,
          &quot;characteristics&quot;: arr[k].slice(2)
        })
    })
    res.sort((a,b) =&gt; a.brand.localeCompare(b.brand))
    res.forEach(e =&gt; e.models.sort((a,b) =&gt; a.model.localeCompare(b.model)))
    return res
   }
  </code></pre>
  <p>I'm trying to understand what is happening here:</p>
  <pre><code>if(-1 === tempIndex) {
    tempIndex = res.push({
      brand:arr[k][0],
      models:[]
    })-1 // what does this do?
  }
  </code></pre>
  <p>What's the purpose of that <code>-1</code> after pushing an element into the array?</p>