Reputation: 977
I recently started doing react native and don't understand as how to debug so as to get my results in console . Here is the result I get in console .
Organizations is [object Object]
How do i get all the content of organizations . I did this in my code for console .
console.log('Organizations is '+organizations);
Upvotes: 35
Views: 72616
Reputation: 608
In ES6 syntaxe you can do something like this :
console.log(`Organisations is : ${JSON.stringify(organisations)}`);
Upvotes: 10
Reputation: 53
use below code to print object in react-native
<View> {(()=>{ console.log(object) })()} </View>
Upvotes: -4
Reputation: 449
Here are all methods to print an object without going mad. Print object in JavaScript
console.log('Organisations is : ' + JSON.stringify(organisations));
Upvotes: 11
Reputation: 1074989
Most consoles look at the argument they're passed and show an intelligent rendering of it, so you may want to provide organizations
directly rather than concatenating it with a string (which will invoke the object's default toString
behavior, which is "[object Object]"
if you haven't done something special). Most also support multiple arguments, so you can do
console.log("Organizations is", organizations);
...to see both your label and the intelligent rendering.
See also this question's answers about console rendering, though.
Upvotes: 8
Reputation: 12884
let organizations = {name: 'McD'}
console.log(organizations)//Without type coercion
console.log('organizations is '+organizations);//Forcefully to convert object to become a string
The problem with console.log('Organizations is '+organizations);
is due to type coercion. You are combining/concatenating a string ('Organizations is ') with an object(organizations) which forcing to convert an object into a string.
Upvotes: 0
Reputation: 681
If you try to log with a string the console tries to convert your object to a string definition automatically.
So either you log the string separately:
console.log('Organizations is');
console.log(organizations);
Or you need to convert your object to a readable format first e.g. JSON:
console.log(JSON.stringify(organizations));
Upvotes: 1