Is it possible to make an expression the left-hand side of an assignment in Javascript?

Why is it not functioning properly?
It is displaying an error.

Error Message: invalid left-hand side in assignment expression

Technology Used: VueJs


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

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

}‍‍‍‍‍‍

Data Configuration:

data () {
  return {
     product: {
       properties:{}
     }
  }
}

Answer №1

Give this a shot:

this.item = {
  attributes: {}
};

for (var index = 0, length = 10; index < length; index++) {
  this.item.attributes["attribute" + index] = '';
}

console.log(this.item);

Answer №2

Setting product properties to an empty string for the specified property

Answer №3

v left-side                                   v right-side
this.product.properties + `.property${i}` = '';

When using Javascript, the left side of the assignment operator must be a variable or object property that can receive a value. You have an addition expression on the left side in your code which is not allowed.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Javascript/Jquery - Eliminating line breaks when transferring text to a textarea by copying and pasting

Is there a method to paste text into a textarea that will automatically remove any line breaks or whitespaces? For instance, if I copy the following text and paste it into the textarea: abcdef, ghijkl, mnopqrs I would like it to appear in the textarea as ...

Help with Vue.js App Deployed on Heroku: How to Fix "Cannot GET /" Error?

When I try to access the URL for my Vue.js application (), it correctly takes me to the homepage. However, clicking on the 'Start' button, which should redirect me to '/test', gives me an error message saying 'Cannot GET /test&apos ...

Converting Latitude and Longitude into a 3D point using three.js

Is there a function available in three.js that can determine the inverse of azimuth and inclination for PolyhedronGeometry calculations? Essentially, I am looking to find the 3D point at a specific angle from the origin based on azimuth and inclination val ...

Route parameters do not function correctly with computed properties

I'm facing an issue with my getter function that stores all products. When I try to retrieve a single product dynamically based on this.$route.params.id, it doesn't return any value. The code works fine when I navigate to a specific product, but ...

The majority of the sliding banner is crafted using 90% HTML and CSS3, with just a touch

I devised a clever script to smoothly slide an image back and forth across the screen using CSS3. Unfortunately, I encountered a problem with CSS animations - they do not support changing the background-image directly. Attempting to overcome this limitatio ...

Issue encountered while fetching data from SQL database in a Node.js application

After successfully connecting the database to my node js project, I encountered an issue when attempting to retrieve data using the get operation. Despite the connection working fine, I was unable to resolve the error that occurred. Establishing the SQL c ...

Learn how to transfer and retrieve data in a different jade template using Node.js without relying on session management or query strings

I am currently facing an issue where I need to redirect and send data from one view to another in a single step using Jade templates. The code snippet below shows my attempt: customer.js var express = require('express'); var router = express.Ro ...

Display a popup box upon receiving the response from an AJAX request

I have successfully implemented an Ajax code that delivers the desired result. Now, I am looking to enhance this code so that when a response is received from Ajax, a popup/modal box will automatically open. Currently, I can manually trigger the opening o ...

Implementing a technique to synchronize table updates with only new or modified data using jQuery and ajax

Just diving into the world of jQuery! Currently, I have a table set up to load data from the server using ajax\jQuery every x seconds. The data is being received in JSON format. My main challenge right now is figuring out how to update only specific ...

Collect the text shown in an alert message created with JavaScript

I'm currently unsure if this is achievable or not. In one of my scenarios, I aim to extract text that appears in alert boxes on external websites by including my JavaScript file. Is there a method to obtain the text content shown in an alert message ...

Manipulating nested JSON objects with AngularJS by adding and pushing the data

I am looking at a JSON object structured like this : { "Name": "Shivansh", "RollNo": "1", "Stream": "CSE", "OverallScore": "76", "Semester": [ { "SemesterName": "FY-2012 - 1", "TotalScore": "78.00", ...

Tips for successfully implementing an Ocrad.js example

I've been working on an OCR (optical character recognition) web application and stumbled upon the Ocrad.js JavaScript library Ocrad.js. It seems like a perfect fit for what I need, but unfortunately, I'm having trouble getting it to function prop ...

Can we modify a currently active document within MongoDB?

Is there a more efficient way to achieve the same functionality in JavaScript? I have to find a user, validate their password, and then update their document. Can I optimize this process by reusing the already retrieved document (stored in var doc) for up ...

Could you confirm if this is a TypeScript function?

Recently, while delving into the vue-next source code, I stumbled upon a particular line that left me puzzled. Due to my limited experience with TypeScript, I found myself struggling to grasp its purpose. Could someone clarify if this snippet constitutes ...

The MongoDB regex is failing to provide the expected outcome

I'm facing an issue with searching data in MongoDB. I have a table with approximately 5000 entries of data that need to be searched based on multiple columns with specific priority criteria. The first priorities for the search are symbol, name, co_nam ...

Can you explain the purpose of the GenericType parameter in a TypeScript promise declaration for me?

I am curious about whether the generic type in Typescript's Promise<GenericType> definition indicates the type of the object passed to the then handler. As an example, consider the following code: const pr:Promise<Array<Number>> ...

Dragging objects on a map is done using jQuery and it causes them to bounce

Currently, I am working on implementing the JQuery Draggable feature. My idea is to create a map where I can attach image Divs to it dynamically using Jquery. So far, I have been successful in adding the Divs and making them draggable around the map effici ...

Converting an array into an object with Express JS: A comprehensive guide

Take a look at my user model to understand the structure of my database. var userSchema = new Schema({ firstName: {type: String, required: true, trim: true}, lastName: {type: String, required: true, trim: true}, address: { street: {type: String, requi ...

Exploring Array Iteration and Incrementing with Easing Techniques

I am currently working on a function that involves iterating over an array and incrementing the values by varying amounts. The challenge is to decrease these incremental amounts as the values in the array get larger. Let's consider the following exam ...

The parent's height dynamically adjusts based on the height of its visible children using only CSS

I am dealing with the following structure: <div class="body"> <div class="wrapper"> <div class="dialog"> <div class="content-0"></div> <div class="content-1&quo ...