About JS error uncaught syntax error: invalid shorthand property initializer

Sometimes when typing JS code, you will often encounter such errors:

This is due to careless typing of code, resulting in grammatical format errors.

If the object literal is used to define the object, the relationship between the attribute name and the attribute value:

<script>
var province = [{
            id: 1002,
            name: 'Heibei',
            city: [{
                    id: 1,
                    name= 'Shijiazhuang' // use object literals to define objects with attribute names separated from attribute values by:.
                },
                {
                    id: 2,
                    name: 'Handan'
                }
            ]
        }];
</script>

Grammar norms are very important. Try not to make mistakes that can be avoided.

Read More: