Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Array Extensions</title>
</head>
<body>
  <script>
    (function() {
      Array.prototype.oddsOnly = function() {
        var rv = [], index;
        for (index = 1; index < this.length; index += 2) {
          rv.push(this[index]);
        }
        return rv;
      };
      
      var a = ["zero", "one", "two", "three", "four", "five", "six"];
      var b = a.oddsOnly();
      display("a: " + a.join(", "));
      display("b: " + b.join(", "));
      function display(msg) {
        var p = document.createElement('p');
        p.innerHTML = String(msg);
        document.body.appendChild(p);
      }
    })();
  </script>
</body>
</html>
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers