I have below the Array that came from the JSON response
{
"websiteId": "4f8b36d00000000000000001",
"date": "2019-04-01T00:00:00.000Z",
"chats": 121,
"missedChats": 0
},
{
"websiteId": "4f8b36d00000000000000002",
"date": "2019-04-01T00:00:00.000Z",
"chats": 13,
"missedChats": 0
},
{
"websiteId": "4f8b36d00000000000000003",
"date": "2019-04-01T00:00:00.000Z",
"chats": 232,
"missedChats": 9
I needed the sum of the 'chats and 'missedChats' per website id. I tried using Array.prototype.reduce() like this
const chatData = fetch('https://bitbucket.org/!api/2.0/snippets/tawkto/aA8zqE/4f62624a75da6d1b8dd7f70e53af8d36a1603910/files/webstats.json');
var sum = JSON.parse(chatData).reduce(function(acc, val){
return acc.chats + val.missedChats;
}, {chats, missedChats: 0});
but I get an error like this
VM362:1 Uncaught SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse (<anonymous>)
at <anonymous>:4:16
Fairly new to JavaScript so any help will be appreciated, thanks.