1

why it doesn't work.
And it shows the Error

invalid left-hand side in assignment expression

VueJs


for (let i = 1; i <= this.properties.length; i++) {

    this.product.properties + `.property${i}` = '';

}‍‍‍‍‍‍

data

data () {
  return {
     product: {
       properties:{}
     }
  }
}
M. Twarog
  • 2,418
  • 3
  • 21
  • 39
Parsa Haghighi
  • 205
  • 1
  • 3
  • 13
  • you can't perform an operation (`+`) before the `=`, to access a property an object dynamically you should always write `myObject[dynamicKeyString]` – Simon Dehaut Oct 10 '19 at 20:39

3 Answers3

3

Try this:

this.product = {
  properties: {}
};

for (var i = 0, len = 10; i < len; i++) {
  this.product.properties["property" + i] = '';
}

console.log(this.product);
Taha Paksu
  • 15,371
  • 2
  • 44
  • 78
1

product.properties[property${i}] = ''

Deepak
  • 141
  • 1
  • 2
0
v left-hand side                            v right-hand side
this.product.properties + `.property${i}` = '';

In Javascript, on left-hand side of assigment operator must be something to which you can assign a value e.g. variable or object property. In your case there is addition expression there which is not valid.

M. Twarog
  • 2,418
  • 3
  • 21
  • 39