Difference between "[Object]" and "Object Object" in Chrome Console?

I have a code similar to the following.

MyRequests.cors_request("POST", APP_CONFIG.APP_URL+"/users/selectAllUsers", null, function ok(users) { $scope.usersNotFiltered = users; console.log('users--->', users); console.log('$scope.userPerSystem--->', $scope.userPerSystem); // delete the items that is already exists in the userPerSystem function filterUsers(element, index, array) { console.log("$scope.usersNotFiltered :: " + users); commonFindAndRemove($scope.usersNotFiltered, 'userId', element.userId); console.log('a[' + index + '] = ' + element.userId); } $scope.userPerSystem.forEach(filterUsers); $scope.users = $scope.usersNotFiltered; }, 

And I run the tihs code and watch the console. What is the difference between "[Object]" and "Object Object" in the chrome console?

Users ---> [Object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object]

$ scope.userPerSystem ---> [Object] 0: Objectlength: 1__proto__: Array [0] redca-ias.concat.js: 5258

<object> Object object, Object object, Object object, Object object, Object object, Object object, Object object, Object object, Object object, Object object, Object object, Object object, Object object, Object object, Object object, Object object, object object ], [object-object], [object-object], [object-object], [object-object], [object-object], [object-object], [object-object], [object-object], [object to object]
+6
source share
1 answer

The first log shows the structure as it is, that is, a living representation of the structure, and the second a string representation of the structure.

 > var arr = [{}, {}, {}]; > arr // simply logs the object as it is > [Object, Object, Object] > arr + '' // converts the structure into string > "[object Object],[object Object],[object Object]" 

You get this result when you concatenate a string with an object:

 "$scope.usersNotFiltered :: " + users 

In the above snippet, JavaScript converts the structure to a string (primitive value), and the string representation of the object to [object Object] . Since the structure is an array of objects, the string representation of each element is combined with,. You get a similar result by calling the Array.prototype.toString() or Array.prototype.join() method:

 > var arr = [1, 2, 3]; > arr.toString() > "1,2,3" > var arrayOfObjects = [{}, {}, {}]; > arrayOfObjects.toString() > "[object Object],[object Object],[object Object]" 
+5
source

Source: https://habr.com/ru/post/986483/


All Articles