简体   繁体   中英

How to delete double quotes in fetched data

I want to delete the double quotes you can see in this example, I don't know if this was efficient way to fetch data and render in to DOM but if you know how to do this fetching proper way please help me.

 async function getJson() { const response = await fetch('https://randomuser.me/api/?results=10'); const data = await response.json(); console.log(data.results); for (let i = 0; i < data.results.length; i++) { document.getElementById('authors').innerHTML += JSON.stringify(data.results[i].name.first + " " + data.results[i].name.last); } } getJson();
 <p id="authors"></p>

What you are doing doesnt make sense. You're using JSON.stringify around just a firstName + {space} + lastName. Just dont do that and you wont get the quotes.

 async function getJson(){ const response = await fetch('https://randomuser.me/api/?results=10'); const data = await response.json(); console.log(data.results); for(let i=0;i<data.results.length;i++){ document.getElementById('authors').innerHTML += data.results[i].name.first + " " + data.results[i].name.last ; } } getJson();
 <p id="authors"></p>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM