简体   繁体   中英

What is the difference between these two objects in Javascript?

While doing console.log two arrays, I'm able to see them in this way:-

在此处输入图像描述

I don't understand the part that when both of them are of type object and have length 2, then why one shows up like (2) [{…}, {…}] and another like [] ?

In JavaScript

[ ]: This called array

Ex. var arr = [1,2,3];

{}: This called object

Ex. var obj= { "name": "hari","age":23};

From your example You can make array of objects

Ex. var arrobj = [ { "name": "hari","age":23},{ "name": "albert","age":50}];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM