title: How do i get rid of extra space in the front and back of a array when select certain number to print
body: <p>I want to return an array containing all the elements of the array located at the given key that are equal to ten. It should print out <code>[10, 10]</code> but the result of my code is <code>[ 10, 10 ]</code> with extra space in the front and back or my code is just wrong. </p>
  
  <pre><code>var obj = {
      key: [1000, 10, 50, 10],
      key2: [],
      key3: "abc"
  };
  
  function isValid(obj, key) {
      var result = []; 
      if (!obj.hasOwnProperty("key") ||
          !Array.isArray(obj[key]) ||
          obj[key].length === 0) {
              return []; //return empty array if those condition meet.
      }
      else {
          for (var i = 0; i &lt; obj[key].length; i++) {
              if (obj[key][i] === 10) {
                  result.push(obj[key][i]); //push the 10 to result empty array.
              }
          }
  
          return result;
      }
  }
  
  var output = isValid(obj, 'key');
  console.log(output); // --&gt; should print out [10, 10]
  </code></pre>