This question already has answers here:
Accessing an object property with a dynamically-computed name
(19 answers)
Closed 4 years ago.
My app in Google Apps Script gets data from a form that I want to process.
The element form is received and contains the different parameters and values.
If I log the element form it looks like {uid=11, tradingname=xxx, email=yyy}
I can pick up the separate values by running form.uid or form.tradingname for example. But what I want is to pick up the parameters from the element form by referring to a String "uid" (because I get this value form the headers row of the spreadsheet).
Is there a simple way I can do this in one line, for example something like:
form.element["uid"]
So far I've only found difficult methods like https://gomakethings.com/how-to-get-the-value-of-a-querystring-with-native-javascript/ and I would think that I should be able to do this in an easier way.
Thanks!
You can use $("#yourform").serializeArray() and then iterate to match "name" values you want
Related
This question already has answers here:
How can I update an object inside of an array in firestore?
(1 answer)
How to update an "array of objects" with Firestore?
(18 answers)
Is there any way to update a specific index from the array in Firestore
(3 answers)
Closed 8 months ago.
i am stuck with a problem with firebase (with Vue). I want to add the user id to a specific map (yes, maybe or no) when the user presses a specific button. But Im having trouble add/update the data because its nested.
Here is my data structure in Firestore
I want to add the user id in a map, something like this:
dates: {
[
0: {
yes: [userId1, userId2]
}
]
}
Does anyone can help me pushing the user ids into the arrays?
Unfortunately, right now it is not possible to update a specific element of the array. You can add new items or remove them - look here. But I would consider a little change in the approach and create a collection called dates in which you can define documents, which will contain yes, no, maybe arrays, which can be easily updated - in the way mentioned before.
This question already has answers here:
Getting JavaScript object key list
(19 answers)
Closed 1 year ago.
I am using the Alpha Vantage API to get stock market data. The data is returned in this format:
For charting purposes, I need to create an array or object of all of the dates. They are not within the actual data objects so I'm not sure how to do this.
For example, for this specific data I would want an array that looks something like this:
['2021-04-26', '2021-04-26', '2021-04-26', '2021-04-26', '2021-04-26', '2021-05-03'...]
Thanks for the help!
You can use Object.keys().
You didn't provide sample json, so this is formatted code and not a snippet.
const dates = Object.keys(data['Time Series (Daily)'])
This question already has answers here:
How to convert URL parameters to a JavaScript object? [duplicate]
(34 answers)
Closed 3 years ago.
I have serialized form in string such as:
"name=Michael&surname=Davies&multiple=selection1&multiple=selection3"
How can I convert this string to object and then change values in form, or directly change values in form with this string? I have several forms in one html page and each string represent values in one form.
Thank you.
Try using below to get an array. Then u can put them in to a JSON object by traversing through the array. May be not the best solution.
$("#form").serializeArray();
This question already has answers here:
read an external local JSON file into Javascript
(4 answers)
Closed 3 years ago.
I have an external JSON file on my server that I want to display the objects from into an HTML document without using JQuery. I specifically just want to call the username object and display it on an "All Users" page for a simple homework project. I've had a difficult time finding ways to do this without JQuery. How could I go about doing this?
JSON Example:
{"name":"asfd","username":"awsf","email":"kean","age":"21","gender":"Male","submit":"Submit"},
{"name":"asdf","username":"asfd","email":"asdf#asdf","age":"21","gender":"Male","submit":"Submit"},
{"name":"null","username":"null","email":"null#gmail.com","age":"21","gender":"Male","submit":"Submit"},
{"name":"null","username":"null","email":"null#gmail.com","age":"21","gender":"Male","submit":"Submit"},
If you have an array of json objects you can loop over it and call JSON.parse() on each. That will give you simple user object that you can access and place in your page his username.
for(var i=0; i<users.length; i++) {
var user = JSON.parse(users[i]);
// you can now access username for each user with user[i].username
// place a username into new element in your page
}
Useful reference for making server call without jQuery : How to make an AJAX call without jQuery?
This question already has answers here:
How do I reference a JavaScript object property with a hyphen in it?
(11 answers)
Closed 8 years ago.
I have a field sent by SERVICE which is having hypen in it. Eg., first-name (As JSON object)
But when I try to get the value of that field through the jsp. I am getting a script error.
Please let me know how to access the hypen also in this?
var nameList = msg.RESPONSE.DATA.NAME-LIST;
The above way when I try to access it is throwing script error
A variable or property name with an hyphen is indeed wrong in javascript (Jquery).
However, you can access the "problematic" property like this :
var nameList = msg.RESPONSE.DATA["NAME-LIST"];
I would recommend to rename the property(ies)
without hyphen if you control the content of this response