I have an array of 3586 objects. The index 0 is SAPATILHA / SHARP BEGE/TABACO and has an array called products that contains 10 items. Could someone explain to me how I can create and save an array containing the products of the selected index?
listarPorReferencia() {
this.linxService.listarPorReferencia().subscribe(data => {
this.aux3 = data;
this.aux3.forEach(element => {
this.novasColecoes.push({ // novasColecoes is the array with 3586 objects
"produtos": element.produtos,
"nome": element.nome,
"referencia": element.referencia,
"selecionado": false
});
})
this.colecoes = this.novasColecoes
this.arrayProdutos.forEach(element => {
if (this.novasColecoes.find(m => m.idProduto == element.LinxProdutosId)) {
this.novasColecoes.find(m => m.idProduto == element.LinxProdutosId).selecionado = true;
}
});
});
}
//The code above is taking the array from the backend
// The below code I try to select products inside the main array
setProduct(product) {
product.forEach(getProducts => {
if(idProducts.includes(getProducts.id)){
this.idProducts = this.idProducts.filter(c => c != getProducts.id);
this.arrayProdutos = this.arrayProdutos.filter(c=>c!=getProducts);
}else{
this.idProducts.push(getProducts.id);
this.arrayProdutos.push(getProducts);
}
})
}