Becky Becky - 4 months ago 6
AngularJS Question

How to split data's which are inside the array

I am trying to print the this array of data. My data looks like this:

[[["Not Critical","Not Critical"]],[["Not Critical","Not Critical"]],[["Not Critical","Not Critical"]]]


I need to print like this: (That means data which is inside every array has to be on the next line),

[
[
[
"Not Critical",
"Not Critical"
]
],
[
[
"Not Critical",
"Not Critical"
]
],
[
[
"Not Critical",
"Not Critical"
]
]
]


The output I am getting is:

[
[
["Not Critical", "Not Critical"]
],
[
["Not Critical", "Not Critical"]
],
[
["Not Critical", "Not Critical"]
]

]


Note : I don't want to print every array on next line, instead of that, the data's which are inside the array's are have to be print in the next line .

Answer

You can use the space parameter in JSON.stringify:

var data = [[["Not Critical","Not Critical"]],[["Not Critical","Not Critical"]],[["Not Critical","Not Critical"]]];

// Your data is now formatted like you want
var formattedData = JSON.stringify(data, null, 2);

// So you can see it...
console.log(formattedData);