How do I print out my object array in React Native Expo?
React JS : Logging the array items in the console
Use comma instead of +.
console.log("listofItems: ", listItems);
This way javascript wont try to convert it to string, and chrome console would let you expand your array of objects
React - Can console log object, but not specific property of said object
When your component is mounted, pokeList is an empty array.
React will run the following block before the useEffect hook has finished running:
const specificPokemon = pokeList.find((pokemon) => {
return pokemon.name === pokeName.pokemon_name;
});
console.log(specificPokemon);
console.log(specificPokemon.name);
As long as your array is empty, specificPokemon
will be undefined
and calling specificPokemon.name
will trigger your error.
Beware with console.log
, its behavior is not always synchronous.
You might think specificPokemon
is properly defined because console.log
won't necessarily show undefined
.
To verify this, use console.log(JSON.stringify(specificPokemon));
.
why i got [object object ]
Use JSON.stringify instead .toString
This question might help you What's the difference in using toString() compared to JSON.stringify()? understand the difference
let x = {a: 123, b: 321};console.log("toString", x.toString());console.log("stringified", JSON.stringify(x));
Related Topics
Change Name of Uploaded File on Client
Run Script After Appending It to the HTML
Best Way to Show a Loading Spinner/Gif While My React Component Is Fetching Via Ajax
How to Save an Image to Localstorage and Display It on the Next Page
Ios Safari/Chrome - Unwanted Scrolling When Focusing an Input Inside the Modal
How to Attach Multiple Images in a Embed
Using JavaScript Node.Js How to Parallel Process for Loops
Only Allowing Numbers Upto Certain Length in Material Ui
Get Selected Item Value from Bootstrap Dropdown With Specific Id
How to Build Pdf File from Binary String Returned from a Web-Service Using JavaScript
Add Hyphen After Every Fourth Character in a String Seperated by Comma
How to Read Data from *.Csv File Using JavaScript
Download Image as File in Typescript
Get Docx File Contents Using Javascript/Jquery
Get Image from Json File Using JavaScript and Display in HTML Img Tag