0

This is the Array I'm trying to map

const arr = [
{"title" : "something",
 "Text" : "something"
},
{"title" : "something",
 "Text" : "something"
},
{"title" : "something",
 "Text" : "something"
}

]

Tried to map it like this

{arr.map((item, index) => {
    return (
      <div key={index}>
         <p>{item.title}</p>
         <p>{item.Text}</p> 
         <button>
           click here 
         </button>
      </div>
    )
})}

It won't work so what am i missing here?

edited*

1
  • 3
    item.text should be item.Text and Const should be const Commented Apr 1, 2022 at 9:58

2 Answers 2

3

Const needs to be lowercase

const arr = [
 { 
   "title" : "something",
   "Text" : "something"
 },
 {
   "title" : "something",
   "Text" : "something"
 },
 {
   "title" : "something",
   "Text" : "something"
 }
];

The Title key in you object is catitalized

{arr.map((item, index) => {
    return (
      <div key={index}>
         <p>{item.title}</p>
         <p>{item.Text}</p> 
         <button>
           click here 
         </button>
      </div>
    )
})}

Or you also can do it like this

{arr.map(({title, Text}, index) => {
    return (
      <div key={index}>
         <p>{title}</p>
         <p>{Text}</p> 
         <button>
           click here 
         </button>
      </div>
    )
})}
Sign up to request clarification or add additional context in comments.

Comments

3

Why your Const is capital, it should be const and item.text should be item.Text

const arr = [
{
 "title" : "something",
 "Text" : "something"
},
{"title" : "something",
 "Text" : "something"
},
{"title" : "something",
 "Text" : "something"
}
]

{arr.map((item, index) => {
    return (
      <div key={index}>
         <p>{item.title}</p>
         <p>{item.Text}</p> 
         <button>
           click here 
         </button>
      </div>
    )
})}

2 Comments

Not sure if this might add value to the above code-snippet.
Sry wrote it wrong... So this should work right with the corrections

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.