Best way to store multiple string arrays and display it in html


sorry for the bad title…. I did not know how to name it.
I have a little problem. I have an array of Strings, and i want to cut this strings into smaller parts. I used a loop and the split method to do this. But split also returns an array.

What is the best way to store those returned arrays so that I can display it afterwards in a table in my html file?

I hope it will be more clear with my code snippet.

books: string[];
booksDetails: string[][];
for (var i = 0; i < books.length ; i++) {
  var bookSplit = books[i].split(/(?:\/|-)+/);

and then display it

    <tr *ngFor="let book of booksDetails; let i = index" []="i">


You’re halfway there, just nest another ngFor-loop on the <td> element:

<tr *ngFor="let book of booksDetails; let i = index" []="i">
  <td *ngFor="let detail of book; let j = index" []="j">

Edit: You can also use instead of the long and unnecessary for-loop:

this.booksDetails = => b.split(/(?:\/|-)+/));

Answered By – michalwa

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published