Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

how to add new index in array in typescript

let currentDate = formatDate(new Date(), 'MM/dd/yyyy', 'en');
    let objPurchare=new PurchaseOrderLineItems();
    objPurchare.Id=obj.Id;
    objPurchare.ItemNo=obj.ItemNo+1;
    objPurchare.MultiReleaseNo=obj.MultiReleaseNo+1;
    objPurchare.DateCreated=obj.DateCreated;
    objPurchare.Partno=obj.Partno;
    objPurchare.OnHold=obj.OnHold;
    objPurchare.Description=obj.Description;
    objPurchare.Supplier=obj.Supplier;
    objPurchare.LastPurchase=obj.LastPurchase;
    objPurchare.OrderQty=0;
    objPurchare.Demand=obj.Demand;
    objPurchare.AvgUsage=parseFloat(obj.AvgUsage).toFixed(4);
    objPurchare.LeadTime=obj.LeadTime;
    objPurchare.OnHand=obj.OnHand;
    objPurchare.PromiseDate= this.datePipe.transform(obj.PromiseDate, 'yyyy-MM-dd'),
    objPurchare.Notes=obj.Notes;
    objPurchare.Checked=false;
    objPurchare.ApplyRedClass=formatDate(obj.DateCreated, 'MM/dd/yyyy', 'en') < currentDate ? true : false;
    objPurchare.BuyerId= obj.BuyerId;
    objPurchare.MultiRelease=0;  
    objPurchare.Addbtn= true;
    objPurchare.IsMultiRelease=false;

    const insert = (arr, index, newItem) => [
      // part of the array before the specified index
      ...arr.slice(0, index),
      // inserted item
      newItem,
      // part of the array after the specified index
      ...arr.slice(index)
    ]   
    this.reOrderQueueList[i].MultiReleaseLineItems=insert(this.reOrderQueueList[i].MultiReleaseLineItems, j+1, objPurchare)

    let counter=1;
    for (let x = 0; x < this.reOrderQueueList[i].MultiReleaseLineItems.length; x++) {
      this.reOrderQueueList[i].MultiReleaseLineItems[x].ItemNo=counter;
      this.reOrderQueueList[i].MultiReleaseLineItems[x].MultiReleaseNo=counter;
      counter++
    }
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #add #index #array #typescript
ADD COMMENT
Topic
Name
6+2 =