“Comment ajouter un nouvel index dans le tableau dans TypeScript” Réponses codées

Comment ajouter un nouvel index dans le tableau dans TypeScript

const items = [1, 2, 3, 4, 5]

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)
]

const result = insert(items, 1, 10)

console.log(result)
// [1, 10, 2, 3, 4, 5]
 Run code snippetHide results
Aamir Farooq

Comment ajouter un nouvel index dans le tableau dans 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++
    }
Aamir Farooq

Réponses similaires à “Comment ajouter un nouvel index dans le tableau dans TypeScript”

Questions similaires à “Comment ajouter un nouvel index dans le tableau dans TypeScript”

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code