Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

125
Visualizações
Getting unwanted commas after div

`

Here's the code written in TypeScript.

This is code to build HTML table which display items from Nested objects. This code works fine but just there is an issue in printing like it should only create table with rows but it is also printing some coma's which are not even part of any line which is executed

import {Component} from '@angular/core';
  
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})

export class AppComponent {
  title = 'Angular';
  data = {
    id: '0001',
    type: 'donut',
    name: 'Cake',
    ppu: 0.55,
    batters: {
      batter: [{
          id: '1001',
          type: 'Regular'
        },
        {
          id: '1002',
          type: 'Chocolate'
        },
        {
          id: '1003',
          type: 'Blueberry'
        },
        {
          id: '1004',
          type: "Devil's Food"
        }
      ]
    },
    topping: [{
        id: '5001',
        type: 'None'
      },
      {
        id: '5002',
        type: 'Glazed'
      },
      {
        id: '5005',
        type: 'Sugar'
      },
      {
        id: '5007',
        type: 'Powdered Sugar'
      },
      {
        id: '5006',
        type: 'Chocolate with Sprinkles'
      },
      {
        id: '5003',
        type: 'Chocolate'
      },
      {
        id: '5004',
        type: 'Maple'
      }
    ]
  };

  //Function which build HTML Table which get's dynamic values.

  htmlStr = (data, wrapperClassName, tableClassName = 'table table-sm') => {
    return `
    <div class=${tableClassName}>
      <table className=${tableClassName}>

        <tbody>

          ${Object.keys(data).map( (k) => `
          <tr>
            ${(!Array.isArray(data) && `
            <td>${k.replace(/_/g, ' ')}</td>`) || ''} ${ data[k] && typeof data[k] === 'object' ? `
            <td>
              ${this.htmlStr(data[k], wrapperClassName, tableClassName)}
            </td>` : `
            <td>
              <span>${data[k] || ''}</span>
            </td>` }
          </tr>` )}
        </tbody>

      </table>

    </div>`;
  };
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

in your code the snippet Object.keys(data).map(.....) converts it to array. Now when you put this array in string literal JavaScript will try to convert it to a string so it will call .toString() on it which joins all the elements of array using , by default.

instead do this Object.keys(data).map(....).join("") this will join array with empty string

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda