I have a json-object which I like to evaluate with javascript. I wrote a script (or copied it from different places of the internet xD) to get the specific values from the object. The script should be used in transformation in the later process.
My code looks like this:
var json = [{"localNumber":"012345","remoteNumber":"012345","date":"2021-06-26T17:55:00+02","type":2,"duration":0}]
var mCalls = '';
var i = 1;
json.forEach((item) => {
if (item.type == 2) {
console.log('Anrufe: ' + item.remoteNumber);
mCalls += 'Anruf '+ i + 'am '+ item.date+ ' von Nummer ' + item.remoteNumber.toString() + ' ';
console.log(mCalls);
i = i+1;
}
})
When i run it on https://onecompiler.com/ works.
If i run it in the script editor from openhab i get the following error message
2021-06-26 18:34:40.927 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID '2e31e320ac' failed: <eval>:4:20 Expected , but found =>
json.forEach((item) => {
^ in <eval> at line number 4 at column number 20
I am not a developer an by far not a developer by for javascript.