JSFiddle - React, Tailwind, and code Playground

by Meir Gabay

JavaScript

var child = function(){
 	this.data = {};
 	this.type = '';
 	this.name = '';
 	this.other = null;
  this.setName = function (myi){
  	this.name = myi;
  }
	this.getName = function (){
  	return this.name;
  },
  this.getObject = function(){
  	return {
    	data: this.data,
      type: this.type,
      name: this.name,
      other: this.other
    }
  }
}

var obj = {
	children: [],
	count: 0,
	countChildren: function(){
  	this.count = this.children.length
    console.log(this.count);
  }
};

for (var i=0 ; i < 5 ; i++){
  obj['children'][i] = {
    child: new child(),
    data: ''
  };
  obj['children'][i].child.setName("my i = " + i);
  //console.log (obj['children'][i].getName());
}

obj.countChildren();
console.log(obj.children[0].child.getObject().name);