1

I got this error

SyntaxError: Unexpected token '}'. Expected a ':' following the property name 'value'.
(anonymous function)

when doing this :

var datas1 = [];
angular.forEach(data.data, function(value, key) {
            if(value.comfi_type_id == "1" || value.comfi_type_id == "3" || value.comfi_type_id == "4")
                datas1.push({value})
        })
        $timeout(function() {
            $scope.items = {'data':{'data1':datas1}};
          }, 1000);

The code run fine on Chrome, but only Safari appeared to be error. Can anyone enlighten me, what is wrong?

Question Update

After I doing this

datas1.push({value:value})

It is now run fine in Safari browser. But now when I tried on ios device (this is ionic app) the code is not functioning. No data is push inside datas1

I thought when everything work on Safari, also work on ios device ?

2 Answers 2

3

Safari probably doesn't support the short object notation ({ value }). You have to specify the key and the value:

datas1.push({ value: value });
Sign up to request clarification or add additional context in comments.

5 Comments

That's great, it is working now. Will mark as answer later :)
@MiG I'd like to add that short object notation is an ES6 feature, so probably best to avoid using it directly if you plan to support multiple browsers.
Hi, I have update my question. The last fix run fine on Safari, but not yet in ios device. Why's that?
It should work. Is the condition fulfilled? Maybe there are some different data.
ahh yeah...I do platform remove ios then re-added, clean and rebuild on xcode. Everything is working fine now. Maybe I too panic :P ..thank you very much
2

I also had this issue. It was because, I was using

var newObj = [];
for (var k in dataArray) {
    newObj.push(datArr[k]);
}

This 'for-loop' creates issue only in Safari and it adds additionally a function object to the array and array length always actual length + 1.

I fixed by replacing this for loop with the below format,

var newObj = [];
for (var k = 0 ; k < dataArray.length; k++) {
    newObj.push(datArr[k]);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.