Search code examples
angularobjectincrement

Anguar-Increment three digits..001,002,003


*Using Algular 10 i am trying to increment "count" inside "fileobj" like 001,002,...010,011...so that i can get in html using ngFor i managed get only 1,2,3....

let docindexNo=1
   for (let i = 0; i < tierdata.length; i++) {
            //for showing fileName count continously
            let filenameArrayforCount=[];
            let docfileNameArrayforCount=[];
            docfileNameArrayforCount=fileNameSeperatedbyComma?.split(',');
            console.log("<<<>>>",docfileNameArrayforCount)
            if(docfileNameArrayforCount)){
            docfileNameArrayforCount.forEach(element => {
              let fileobj={
                count:this.docindexNo,
                fileName:element,
              }
              filenameArrayforCount.push(fileobj)
              this.docindexNo++;
            });
          }

Solution

  • Use padStart:

    count: this.docindexNo.toString().padStart(3, '0'),