How to save an array inside another array and then save to Firebase

0

Help! I have this snippet of code to store the following:

    var company = {
      description: "",
      logoPath: "",
      logoUrl: ""
    };
    var companiesArray = {
      length: 0,
      addElem: function addElem(elem) {
        [].push.call(this, elem);
      }
    };
    for (var i = 1; i < 10; i++) {
      company.description = "descripcion";
      company.logoPath = "/urlpath/img.png";
      company.logoUrl = "http://domain.com";
      companiesArray.addElem(company)
    }
    // Luego, tengo que recuperar companiesArray.company para registrarlo en la base de datos Firebase.
    console.log(companiesArray.company); //undefinied

What would be the problem?

    
asked by Filomon Fernandez 20.07.2018 в 12:40
source

1 answer

0

I have changed your proposal a bit and I have left it like this, to see if it meets your requirements.

var company = {
	description: '',
	logoPath: '',
	logoUrl: ''
};

// companiesArray ahor tienen un array de items, en este caso de companies
var companiesArray = {
	length: 0,
	items: []
};

for (var i = 1; i < 10; i++) {
	company.description = 'descripcion';
	company.logoPath = '/urlpath/img.png';
	company.logoUrl = 'http://domain.com';
  companiesArray.length++;
	companiesArray.items.push(company)
}

// El primero
console.log(companiesArray.items[0]); 
    
answered by 20.07.2018 в 13:33