Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="This bin is an example of a very bad foreach loop">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.3.0/knockout-min.js"></script>
  <div data-bind="foreach: {data: things, as: 'thing'}">
    <div data-bind="text: thing"></div>
  </div>
  <button data-bind="click: moreThings">Do it!</button>
</body>
</html>
 
// noprotect
function ViewModel () {
  var self = this;
  self.things = ko.observableArray([1,2]);
  
  self.moreThings = function () {
    for (i = 0; i < 1000 * 10; i++) {
      self.things.push(i + 2);
    }
  }
}
ko.applyBindings(new ViewModel());
Output

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

Dismiss x
public
Bin info
jlaustillpro
0viewers