When pushing an object into the array, in principle it is the same json object as I marked in the picture below
But the printed one changes and becomes a Array-like. May I ask what is the reason. Is there any way to solve this problem. Make it a json
Use JSON.stringify() to convert again
If you want to print it out in JSON format, please convert it directly to a JSON string for printing.
json definition json
This is not an array-like array. This is an array of array elements
对象
.arr[0] refers to { a: 0 }
As for what is displayed
Object
字眼 指代的是类型
There is no problem with this. You put 3 objects in the array. Shouldn’t this array be
[对象1,对象2,对象3]
?This is still a standard array. As for the concept of array-like, please visit Baidu.
What you want
[{a:0},{a:1},{a:2}]
is just the way we use literals to create data and objects. This does not represent its presentation form.Since the writing method of our literal form is similar to the format of json, it can be converted into a json string to view. This is the format you want.
I just read your reply to others. It seems that you don’t understand the difference between json and js objects.
I have written an article before about JavaScript objects and JSON for your reference.
The json printed by the console is different from the json you wrote. If you look at the json you want to get directly, it is exactly the same as the json you get by pushing.