console.log showing contents of array object

后端 未结 7 1812
没有蜡笔的小新
没有蜡笔的小新 2021-01-30 16:02

I have tried using console.log so I can see the content of my array that contains multiple objects. However I get an error saying console.log is not an

7条回答
  •  情歌与酒
    2021-01-30 16:51

    Json stands for JavaScript Object Notation really all json is are javascript objects so your array is in json form already. To write it out in a div you could do a bunch of things one of the easiest I think would be:

     objectDiv.innerHTML = filter;
    

    where objectDiv is the div you want selected from the DOM using jquery. If you wanted to list parts of the array out you could access them since it is a javascript object like so:

     objectDiv.innerHTML = filter.dvals.valueToDisplay; //brand or count depending.
    

    edit: anything you want to be a string but is not currently (which is rare javascript treats almost everything as a string) just use the toString() function built in. so line above if you needed it would be filter.dvals.valueToDisplay.toString();

    second edit to clarify: this answer is in response to the OP's comments and not completely to his original question.

提交回复
热议问题