how to display the entire object in console in react native
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);
You can stringify it.
console.log(JSON.stringify(organizations));
if you want some formatting
console.log(JSON.stringify(organizations, null, 2));
Here are all methods to print an object without going mad. Print object in JavaScript
console.log('Organisations is : ' + JSON.stringify(organisations));
In ES6 syntaxe you can do something like this :
console.log(`Organisations is : ${JSON.stringify(organisations)}`);
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.
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));
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.
use below code to print object in react-native
<View> {(()=>{ console.log(object) })()} </View>