I have information stored in a json file that is accessed through axios calls and mock.js and I am able to access my information. This is the data:
information: {
name: 'Company name',
aboutParagraphs: [
["X"],
["Y"],
["Z"],
["XX"]
],
When I try accessing the whole array, it returns all items.
However, when I try accessing a single array, say information.aboutParagraphs[0], React returns an error TypeError: Cannot read property '0' of undefined.
Here is the code:
<div className="col-lg-6">
<div className="mi-about-content">
<h3>
{information.name}
</h3>
<p>
{information.aboutParagraphs[0]}
</p>
</div>
</div>
I tried checking other solutions but they all seemed to have either a syntax issue or were using the wrong brackets which isn't the case here - as far as I can tell. What am I missing? Is it a syntax issue? Thanks in advance.
{information?.aboutParagraphs[0]}to prevent displaying a property of an undefined information. About the problem, one of my guess is that this object received something else than an array in the first place, which lead to an error, then the correct format is inserted in your object, hence you see the good results in your logging.{ information && Array.isArray(information.aboutParagraphs) ? information.aboutParagraphs[0][0] : 'there is an issue' }