添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
没有腹肌的开水瓶  ·  Exception in thread ...·  6 月前    · 
奋斗的豆腐  ·  ConvertTo-Html ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have an array of values in my React app [profile1, profile2, profile3] read from a database and I need to convert these to a json object that can be used in a third party component. The resultant json needs to be:

{profile1: "profile1", profile2: "profile2", profile3: "profile2"}

I am unfamiliar with JavaScript and React.

Welcome to Stack Overflow! Please take the tour (you get a badge!) and read through the help center, in particular How do I ask a good question? Your best bet here is to do your research, search for related topics on SO, and give it a go. If you get stuck and can't get unstuck after doing more research and searching, post a minimal reproducible example of your attempt and say specifically where you're stuck. People will be glad to help. – T.J. Crowder Sep 4, 2020 at 11:37 FWIW: JSON is a textual notation for data exchange. (More here.) If you're dealing with JavaScript source code, and not dealing with a string, you're not dealing with JSON. – T.J. Crowder Sep 4, 2020 at 11:37 What is profile1, profile2, etc? A variable? A string? In your example it looks like variables. It's usually not possible to get the name of a variable. Please provide a more complete example. – Felix Kling Sep 4, 2020 at 11:51 No need to lash out. The title says "Need help converting a React array to a JSON object with same key and value please" . "I also said that they were values from a database" But that doesn't tell me whether you are getting the whole array from the database or whether you are putting three values from the database into an array. Lots of people say one thing and mean another. That's why we comment and ask for clarification, to make sure we are all on the same page. You could have just clarified that the data you have is (maybe) ["profile1", "profile2", "profile3"]. – Felix Kling Sep 4, 2020 at 12:27 please give answer in proper detail. Check this link for details. stackoverflow.com/help/how-to-answer – DaniyalAhmadSE Sep 4, 2020 at 12:00 This is perfect thanks for you help - I knew it would be simple just didn't know the syntax – Gary Evely Sep 4, 2020 at 12:02

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.