Angular 6 : Find value from existing array, Update array value

Angular 6 : Find value from existing array, Update array value 


Find value from existing array, Update array value  in Angular 6, here I explained step by steps.


let ProductSizes = Array<Size>();
let productSize = new Size();
 
productSize.Quantity = size.Quantity;
productSize.SizeName = size.SizeName;
productSize.sizeId = size.sizeId;
     
Check Value from existing array     
let existingSize = this.ProductSizes.find(item=> item.sizeId== sizeId);

if(existingSize != null)
{
  let sizeIndex = this.ProductSizes.indexOf(existingSize);
  this.ProductSizes[sizeIndex] = productSize;
}
else
{
 this.ProductSizes.push(productSize);
}

  
Hope this will help you and save your time.

Enjoy !!!

:)

No comments:

Post a Comment