Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

how to add new index in array in 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
Comment

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++
    }
Comment

PREVIOUS NEXT
Code Example
Typescript :: sonar ignore rule 
Typescript :: create and return a merged list of all the elements in sorted order 
Typescript :: react native elements button with icon 
Typescript :: react-scripts 
Typescript :: angular host binding class on input 
Typescript :: serenity grid remove button 
Typescript :: react onclick typescript type 
Typescript :: plot a column aginst its frequency in pandas 
Typescript :: ts date get hour 
Typescript :: adding paragraphs with foreach in angular docx.js 
Typescript :: Read file contents on module location 
Typescript :: set array of objects in localstorage 
Typescript :: using chai in typescript 
Typescript :: ion2 calendar locale 
Typescript :: adonis model use transaction 
Typescript :: why do giant covalent structures have high boiling points 
Typescript :: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.16 
Typescript :: sklearn tsne 
Typescript :: install eslint for typescript 
Typescript :: angular calculate difference between two dates 
Typescript :: hthe cmd to create tsconfig.json 
Typescript :: loop through object typescript 
Typescript :: express typescript error handling 
Typescript :: node typescript 
Typescript :: how to check typescript version for my react-app 
Typescript :: round up number typescript 
Typescript :: powershell script remove directory recursive 
Typescript :: typescript check undefined 
Typescript :: regular expression starts and ends with same symbol 
Typescript :: type script encode url 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =