Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
like image 809
jammy Avatar asked Jun 18 '18 07:06

jammy


People also ask

How do I display data in console in react native?

For the android emulator, Click on the emulator screen and Press Control + M ( Ctrl + M ), After open the dialog option select Remote JS Debugging. This will open a resource, http://localhost:8081/debugger-ui on localhost. From there, use the Chrome Developer tools JavaScript console to view console.

How do I view objects in console?

Answer: Use console. log() or JSON. stringify() Method You can use the console. log() method, if you simply wants to know what's inside an object for debugging purpose. This method will print the object in browser console.

How do I display list of items in react native?

React Practice Course. We will import List in our Home component and show it on screen. To create a list, we will use the map() method. This will iterate over an array of items, and render each one. When we run the app, we will see the list of names.


4 Answers

You can stringify it.

console.log(JSON.stringify(organizations));

if you want some formatting

console.log(JSON.stringify(organizations, null, 2));
like image 96
agenthunt Avatar answered Oct 10 '22 13:10

agenthunt


Here are all methods to print an object without going mad. Print object in JavaScript

console.log('Organisations is : ' + JSON.stringify(organisations));
like image 20
patidarsnju Avatar answered Oct 10 '22 13:10

patidarsnju


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.

like image 6
T.J. Crowder Avatar answered Oct 10 '22 14:10

T.J. Crowder


In ES6 syntaxe you can do something like this :

console.log(`Organisations is : ${JSON.stringify(organisations)}`);
like image 6
Eudz Avatar answered Oct 10 '22 14:10

Eudz