When I print array on Chrome console, It is added unexpected value end of array. Here is my screenshot. When I execute step by step using breakpoint in Chrome console, it works correct.
But when I execute not using breakpoint, new values were added at the end of each array.
I don't know that's why. Please help me.
Here is code.
var sample2 = {
"menus": [
{
"command": "formatblock",
"header": "- formatting -",
"values": {
"h1": "Title 1 <h1>",
"h2": "Title 2 <h2>",
"h3": "Title 3 <h3>",
"h4": "Title 4 <h4>",
"h5": "Title 5 <h5>",
"h6": "Title 6 <h6>",
"p": "Paragraph <p>",
"pre": "Preformatted <pre>"
}
},
{
"command": "fontname",
"header": "- font -",
"values": [
"Arial",
"Arial Black",
"Courier New",
"Times New Roman"
]
},
{
"command": "fontsize",
"header": "- size -",
"values": {
"1": "Very small",
"2": "A bit small",
"3": "Normal",
"4": "Medium-large",
"5": "Big",
"6": "Very big",
"7": "Maximum"
}
},
{
"command": "forecolor",
"header": "- color -",
"values": {
"red": "Red",
"blue": "Blue",
"green": "Green",
"white": "White",
"black": "Black"
}
},
{
"command": "backcolor",
"header": "- background -",
"values": {
"white": "White",
"red": "Red",
"green": "Green",
"black": "Black"
}
}
],
"buttons": [
{
"text": "Clean",
"command": "cleanDoc",
"image": "icons\/clean.gif"
},
{
"text": "Print",
"command": "printDoc",
"image": "icons\/print.png"
},
{
"text": "Undo",
"command": "undo",
"image": "icons\/undo.gif"
},
{
"text": "Redo",
"command": "redo",
"image": "icons\/redo.gif"
},
{
"text": "Remove formatting",
"command": "removeFormat",
"image": "icons\/format.png"
},
{
"text": "Bold",
"command": "bold",
"image": "icons\/bold.gif"
},
{
"text": "Italic",
"command": "italic",
"image": "icons\/italic.gif"
},
{
"text": "Underline",
"command": "underline",
"image": "icons\/underline.gif"
},
{
"text": "Left align",
"command": "justifyleft",
"image": "icons\/justifyleft.gif"
},
{
"text": "Center align",
"command": "justifycenter",
"image": "icons\/justifycenter.gif"
},
{
"text": "Right align",
"command": "justifyright",
"image": "icons\/justifyright.gif"
},
{
"text": "Numbered list",
"command": "insertorderedlist",
"image": "icons\/numberedlist.gif"
},
{
"text": "Dotted list",
"command": "insertunorderedlist",
"image": "icons\/dottedlist.gif"
},
{
"text": "Quote",
"command": "formatblock",
"value": "blockquote",
"image": "icons\/quote.gif"
},
{
"text": "Delete indentation",
"command": "outdent",
"image": "icons\/outdent.gif"
},
{
"text": "Add indentation",
"command": "indent",
"image": "icons\/indent.gif"
},
{
"text": "Hyperlink",
"command": "createLink",
"image": "icons\/hyperlink.gif"
},
{
"text": "Cut",
"command": "cut",
"image": "icons\/cut.gif"
},
{
"text": "Copy",
"command": "copy",
"image": "icons\/copy.gif"
},
{
"text": "Paste",
"command": "paste",
"image": "icons\/paste.gif"
}
]
}
function createRow(input, output, parent, id, d, key) {
id = output.length;
var newRow = [id, d, parent, key, getEntityType(input)];
if(getEntityType(input) === "String") newRow.push(input);
return newRow;
}
function obj2Array2(input, output, parentID, id, d, self) {
if (output == undefined) { var output = []; }
if (!d) { var d = 0; }
d = d + 1;
if (parentID == undefined) {
var parentID = "root";
};
newRow = createRow(input, output, parentID, id, d, self)
output.push(newRow);
if (getEntityType(input) === 'Object') {
for (var key in input) {
if (!input.hasOwnProperty(key)) continue;
obj2Array2(input[key], output, self, id, d, key);
}
} else if (getEntityType(input) === "Array") {
for (var i = 0; i < input.length; i++) {
obj2Array2(input[i], output, self, id, d, i);
}
}
return output;
}
var outputArray = obj2Array2(sample2, []);
console.log(outputArray)