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

166
Visualizações
How to add character to the end of the line in node js or javascript

I have a file that has 6,000 of json. Its raw data and I need to add an comma ' , ' to the end of each line. Can someone help. Current code is creating a new line with a comma I need comma at end of each line. Node js or Javascript example is acceptable

The data file:

{"id": "67", "ac": []}
{"id": "78","ac": []}
{"id": "90", "ac": []}

What I am currently getting:

{"id": "67", "ac": []}
,
{"id": "78","ac": []}
,
{"id": "90", "ac": []}

What I need

{"id": "67", "ac": []},
{"id": "78","ac": []},
{"id": "90", "ac": []},

Current code

"use strict";

const fs = require("fs");

fs.readFile("users.json", (err, data) => {
  if (err) throw err;
  let student = data.toString();

  var lines = student.split(/(\n|\r\n)/);

  var new_content = lines
    .map(function (line) {
      return line + ",";
    })
    .join("\r\n");
  fs.writeFile("newFile.json", new_content, (err) => {
    if (err) throw err;
    console.log("Data written to file");
  });
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Looking at your code, it looks like your trying to mutate a string by adding the comma in the map function. 'line' is immutable so you cant add the comma, but you can reassign the value; I.E line = line += ',' or newValue = line += ',' then return the value after that.

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