JSFiddle - React, Tailwind, and code Playground

by Marco Iamonte

JavaScript

function MyClass1 (id){
    this.id = id;
    this.x = 100;
    this.score = 0;
    //some code. not important
}

MyClass1.prototype.updateScore = function (s){
    this.score = s;
};


var arr = [];
for (var i = 0; i < 8; i++){
  var c = new MyClass1(i);
  arr.push (c);
}

var getMyClassesById = function(/* int */ id){
    var size = arr.length;
    for (var i = 0; i<size; i++){
       if (id == arr[i].id){
          return arr [i];
       }
      }
}

console.log(arr);
console.log(getMyClassesById(3));