I try to build and a JSON object which eventually will save to a file. But I found out if I use to approach one "element+= element", it will throw "Invalid string length" String. But for approach 2, I can concat a very long String and save a file. (The file is approximate 50mb). So i want to know what is wrong with my first approach?
const person = {
id: 1,
name: "john"
}
personJson = JSON.stringify(person);
personJson = personJson + ',';
let element = personJson;
for (let index = 0; index < 500; index++) {
element += element;
}
let element = personJson;
for (let index = 0; index < 100000; index++) {
element = element + personJson;
}