JSFiddle - React, Tailwind, and code Playground
JavaScript
let object = {
"@context": "https://schema.org",
"@graph": [
{
"@type": "WebPage",
"@id": "id234234",
"url": "https://www.whatevver.com",
"inLanguage": "de-DE",
"name": "this is the name",
"isPartOf": {
"@id": "id234234" // MAKE IT AS A STRING
},
"primaryImageOfPage": {
"@id": "id234234"
},
"datePublished": "2020-01-14T07:46:12+00:00",
"dateModified": "2020-01-15T08:04:50+00:00",
"description": "description "
},
]
}
console.log(object)
const getpublishedDate = () => {
let publishedDate = "";
const yoastInfo = object
vars = yoastInfo["@graph"];
for(var i in vars) {
if(vars[i]['@type'] === 'WebPage') {
publishedDate=(vars[i]['datePublished']);
}
}
console.log(publishedDate)
return publishedDate;
}
getpublishedDate()