I create an empty array, create object, drop existing key:value data into the object, push object into array, sort the array's objects by one key:value pair, stringify the array, and console.log it.
This all works fine. But if I try to insert a newline using \n the data inside each object is no longer returned when I console.log the stringified array. Instead, I just get [object, Object] on the console.
I've tried to put \n everywhere. Inside the created object as "\n" and also as \n. After the created object as "\n" or \n. Before I stringify, after I stringify. Nothing seems to work.
//create new empty array called indices
var indices = [];
//create new object called newobject and fill it with key:value pair data
var newobject = { name: y[i].Name, age: y[i].age };
//push newobject into indices array
indices.push(newobject);
//create new object called newobject2 and fill it with key:value pair data
varnewobject2 = { country: y[i].Name, age: y[i].age, height: y[i].height };
//push newobject2 into indices array
indices.push(newobject2);
//sort objects in indices array by age values lowest to highest
indices.sort((a, b) => a.age - b.age);
//new variable called output is the sorted indices array stringified
var output = JSON.stringify(indices);
//console.log variable output
console.log(output);
I want each created object in the array to print to a new line when I console.log the stringified array all these new objects are sitting in. The above code works. I just have no idea where or how to insert a line break after each new object. Whenever I try to insert \n the output given reads as:
[output Output]
Thanks for your kind consideration.
console.tableto show the object in table format