Object list with dynamic key names

I have implemented a 'meta' modal box using both bootstrap and angularjs. My current goal is to utilize this setup for saving entered details and sending them to the web API that is running behind the scenes. The functionality works perfectly, but since it's a 'meta' modal intended for various data entry methods, I need to dynamically generate the key of the posted data. For example:

var dataSender = [{ ID: $scope.iUserItem, ClientName: userItem.Name }];

The ClientName property needs to be changed dynamically each time. Is there a way to pass a variable into this section, or do I need to write separate post requests for each piece of 'meta' data being sent?

Answer №1

It is recommended to create your object separately.

var newObj = {};
var companyName = "SecondValley";
newObj[companyName] = "information"; // { "SecondValley" : "information"};
var infoProvider = [newObj];

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

The <script> element failed to close correctly

Within my default.jspx file, which serves as the foundational layout for the page, I am attempting to import several jQuery libraries. The code snippet looks like this: <head> ... <spring:url value="/resources/js/lib/jquery-1.9.1.min.js" ...

Tips for formatting a phone number using regular expressions in [Vue 2]

I am currently working on creating regex code that will meet the following requirements: Only allow the first character (0th index) in a string to be either a '+' symbol or a number (0-9). No non-numerical values (0-9) should be allowed anywhere ...

Using JavaScript import may encounter issues when trying to access the same file or a different file

When importing something and using it, there are certain scenarios where it may not work as expected. For example: <html> <body> <button onclick="foo()">Click Me</button> </body> <script type="module"> ...

Jsdelivr does not automatically synchronize with updates made to GitHub commits

Check out this JavaScript file I have stored on GitHub. // Remember to define the function before setup() and call it under draw() function pointCoord() { stroke(255,0,0); line(mouseX,0, mouseX, height); line(0,mouseY, width, mouseY); ...

What is the process for removing a key from an object and replacing it with its corresponding value?

My JSON sample looks like this: var obj={ "results":{ "grade":"A", "marks":12 }, "data":{ "name":"sam", "gender":"male", "age":10 } }; I am trying to transform the above JSON to: var obj={ "res ...

What is the best way to retrieve all collections and their respective documents in Firestore using cloud functions?

Seeking to retrieve an array structured as [1year, 1month, etc] with each containing arrays of documents. Currently encountering a challenge where the returned array is empty despite correct snapshot sizes. Unsure if issue lies with push() method implemen ...

Resolve React Issue: Using Functions as React Children is Invalid

As I follow along with a React tutorial, I encountered an error while adding a POST request: Functions are not valid as a React child. This may happen if you return a Component instead of from render. Or maybe you meant to call this function rather than ...

Encountered a 404 error while attempting to build and serve a Vue.js project using 'npm build' in Apache Tomcat

After setting up a Vue.js project, the configuration in the package.json file looks like this: "scripts": { "serve": "vue-cli-service serve", "build": "vue-cli-service build", "lint": ...

What are the issues with the latest API routing in Next.js?

I am encountering an error that says: SyntaxError: Unexpected token s in JSON at position 0 Here is my code: import { PrismaClient } from '@prisma/client'; import { IDPay } from 'idpay'; import { NextResponse } from 'next/server&ap ...

Is there a button that allows updating the text in a search field by entering multiple values one after the other?

Is it possible to insert multiple values sequentially into the search field using the same button? For example: value 1, value 2, value 3... Check out a demo here <form id="form1" name="form1" method="post"> <p> <input type=" ...

What is the significance of including the Angular component selector in HTML?

I'm brand new to Angular and html/html5, so please bear with me if my questions seem basic. I've included a screenshot below: https://i.sstatic.net/UXobT.png Here are the questions on my mind: Q1- The component selector name paproductform is n ...

Harness the power of Bootstrap 5.3 color modes based on the user's browser

It has come to my attention that Bootstrap 5.3 introduces support for a customizable color scheme, allowing me to personalize various key features. Interestingly, the default dark theme now relies on the explicitly defined bs-theme data attribute rather t ...

What are some best practices for implementing a checkbox within an editableCellTemplate?

Take a look at this code snippet: { name: 'Calculation Method', field: 'feeType', enableCellEdit: true, editableCellTemplate: 'ui-grid/dropdownEditor' ...

Discover the way to utilize the java enum toString() function in jQuery

In my Java Enum class called NciTaskType, I have defined two tasks: Pnd Review Woli and Osp Planning. public enum NciTaskType { PndReviewWoli, // 0 OspPlanning, // 1 ; @Override public String toString() { switch (this) ...

Ways to clearly establish the concept of "a"

module.exports.getData = function (id) { const userData = require("./data/Users.json"); if (userData.find(user => user.uid === id)) { return user.name; } else return "User"; } I'm trying to display the name of a user, but the consol ...

Is there a way to open various href links with distinct images using window.open?

I am facing some limitations with the program, therefore it would be preferable if the solution does not require JQuery, as mentioned earlier. There are certain restrictions that need to be taken into consideration. My objective is to: Dynamically c ...

Is the Angular index detection failing due to issues with the $$hasKeys property in indexOf()?

Scenario: role: { roleid=3, name="admin"} availableRoles: [ { roleid=3, name="admin", $$hashKey="object:222"}, { roleid=4, name="plain user", $$hashKey="object:223"} ] currentRoles: [ { roleid=3, name="admin"} ...

Jasmine - A guide to error testing techniques

SCENARIO: Hey everyone! I'm currently diving into Jasmine to test my Angular application. I've created a simple function that multiplies two numbers. If the input parameters are not numbers, the function throws an error. Next, I wrote two basi ...

Is there a way to dynamically change the helperText of a Material UI TextField using its current value through code?

I'm currently attempting to dynamically change the helperText of a Material UI TextField based on the value entered into the field. Below is my current implementation: const defaultScores = { STR: 10, DEX: 10, CON: 10, INT: 10, WIS: 10, CH ...

Leveraging Angular Templates

Looking to render a template using Angular in conjunction with a Node.js application. Considering a method to require('angular') from the Node application and utilize its compile service for compiling an email template to then send the email wit ...