You can use .map()
for this. It passes the index into the callback.
myArray = myArray.map((str, index) => ({ value: str, id: index + 1 }));
More Related Contents:
- How do I return the response from an Observable/http/async call in angular?
- How to load external scripts dynamically in Angular?
- Property ‘…’ has no initializer and is not definitely assigned in the constructor
- Angular 2 Sibling Component Communication
- Angular 2: How to detect changes in an array? (@input property)
- Angular: Can’t find Promise, Map, Set and Iterator
- Angular 4.3.3 HttpClient : How get value from the header of a response?
- Angular 2 router event listener
- In Angular, how do you determine the active route?
- Angular2 component’s “this” is undefined when executing callback function
- Angular 2: TypeError: l_thing0 is undefined in [{{thing.title}} in AppComponent@4:44]
- Load existing components dynamically Angular 2 Final Release
- Angular 5 Scroll to top on every Route click
- How to handle window scroll event in Angular 4?
- Nested arrays in Angular 2 reactive forms?
- Call a function on click event in Angular 2
- Angular 4 Filter Search Custom Pipe
- Correct way Provide DomSanitizer to Component with Angular 2 RC6
- Angular 2 typescript invoke javascript function
- How to Pass data from child to parent component Angular
- Angular2 too many file requests on load
- Generate dynamic css based on variables angular
- Angular 6: ERROR TypeError: “… is not a function” – but it is
- Angular interceptor exclude specific urls
- Angular 8 – Lazy loading modules : Error TS1323: Dynamic import is only supported when ‘–module’ flag is ‘commonjs’ or ‘esNext’
- How to iterate using ngFor loop Map containing key as string and values as map iteration
- Plain Javascript as Angular 2 service
- How to check empty object in angular 2 template using *ngIf
- Angular: 7.2.1 ES6 class ReferenceError : Cannot access ‘X’ before initialization
- angular 2 access ng-content within component