I just want to display the dt
property however I get undefined
in my console.
This is an example of the json data when I search toothbrush
[
{
"meta": {
"id": "toothbrush",
"uuid": "b778955b-4d66-4082-84d3-14d5cd81f02c",
"sort": "200277700",
"src": "collegiate",
"section": "alpha",
"stems": [
"toothbrush",
"toothbrushes"
],
"offensive": false
},
"hwi": {
"hw": "tooth*brush",
"prs": [
{
"mw": "\u02c8t\u00fcth-\u02ccbr\u0259sh",
"sound": {
"audio": "toothb01",
"ref": "c",
"stat": "1"
}
}
]
},
"fl": "noun",
"def": [
{
"sseq": [
[
[
"sense",
{
"dt": [
[
"text",
"{bc}a brush for cleaning the teeth"
]
]
}
]
]
]
}
],
"date": "1690",
"shortdef": [
"a brush for cleaning the teeth"
]
}
]
This is my code
<!DOCTYPE html>
<html lang="en">
<head>
<style>
.header {
overflow: hidden;
background-color: rgb(245, 244, 244);
padding: 20px 10px;
}
/* Style the header links */
.header a {
float: left;
color: black;
text-align: center;
padding: 12px;
text-decoration: none;
font-size: 18px;
line-height: 25px;
border-radius: 4px;
}
/* Style the logo link (notice that we set the same value of line-height and font-size to prevent the header to increase when the font gets bigger */
.header a.logo {
font-size: 25px;
font-weight: bold;
}
/* Change the background color on mouse-over */
.header a:hover {
background-color: rgb(245, 244, 244);
color: black;
}
/* Style the active/current link*/
.header a.active {
background-color: dodgerblue;
color: white;
}
/* Float the link section to the right */
.header-right {
float: right;
}
/* Add media queries for responsiveness - when the screen is 500px wide or less, stack the links on top of each other */
@media screen and (max-width: 500px) {
.header a {
float: none;
display: block;
text-align: left;
}
.header-right {
float: none;
}
.div{
width: 80px;
height: 80px;
}
}
</style>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<title>My Dictionary</title>
</head>
<body>
<div class="header">
<a href="#default" class="logo">
<div><img src="https://www.nicepng.com/png/detail/793-7936442_book-logo-png-books-logo-black-png.png" alt="A book"style="width: 80px;px;height: 80px;px;"></div><h1>DictVerse</h1>
</a>
<div class="header-right">
<a class="active" href="#home">Home</a>
<a href="#Dictionary">Dictionary</a>
</div>
</div>
<h4 >Welcome <%=name%></h4>
<div>
<form action="/login?_method=DELETE" method="POST">
<button type="submit">Log Out</button>
</form>
</div>
<input id="in">
<button onclick="defineIt()"defineIt>Search</button>
<div id="out"></div>
<p id="demo"></p>
<script>
async function getData(){
const api_url = 'https://dictionaryapi.com/api/v3/references/collegiate/json/toothbrush?key=4502863e-a238-4f32-b67a-df35b17b2cce'
const response = await fetch(api_url);
const data = await response.json();
var obj = { "name":"John", "age":30, "city":"New York"};
var myJSON = (data);
var myJSON = JSON.stringify(data[0].def[0].sseq[0].sense);
document.getElementById("demo").innerHTML = myJSON;
console.log(myJSON);
}
getData();
</script>
</body>
</html>`enter code here`