Linked Questions
1,026 questions linked to/from Accessing an object property with a dynamically-computed name
1745
votes
9
answers
1.5m
views
JavaScript set object key by variable [duplicate]
I am building some objects in JavaScript and pushing those objects into an array, I am storing the key I want to use in a variable then creating my objects like so:
var key = "happyCount";
myArray....
490
votes
3
answers
674k
views
JavaScript object: access variable property by name as string [duplicate]
If I have a javascript object that looks like below
var columns = {
left: true,
center : false,
right : false
}
and I have a function that is passed both the object, and a property name like so
...
163
votes
10
answers
479k
views
How to get value in an object's key using a variable referencing that key? [duplicate]
I have an object and I can reference key a as in the following:
var obj = {
a: "A",
b: "B",
c: "C"
}
console.log(obj.a); // return string : A
I want to get the ...
87
votes
3
answers
147k
views
How to access object using dynamic key? [duplicate]
How to access an object using a variable as key. Here is my code sample:
var o = {"k1": "111", "k2": "222"};
alert(o.k1); //working fine
var key = "k"+1; alert(key); // k1
alert(o.key); //not working
23
votes
2
answers
20k
views
how to access object property using variable [duplicate]
I have an object
var Messages = {
'fullName' : 'Tell us your cool name dude..! e.g. Yousuf Iqbal',
'userName' : 'Choose a catchy username. Remember! It should be available :)',
'password' : 'Choose ...
21
votes
2
answers
75k
views
get value with string key in javascript [duplicate]
I can't figure out how to get an object property using a string representation of that property's name in javascript. For example, in the following script:
consts = {'key' : 'value'}
var stringKey = ...
17
votes
2
answers
53k
views
How to refer to object fields with a variable? [duplicate]
Let's asume that I have an object:
var obj = {"A":"a", "B":"b", "x":"y", "a":"b"}
When I want to refer to "A" I just write obj.A
How to do it when I have key in a variable, i.e.:
var key = "A";
Is ...
2
votes
4
answers
37k
views
JSON values parsed as undefined in javascript [duplicate]
I am trying to parse a JSON in Javascript. The JSON is created as an ajax response:
$.ajax(url, {
dataType: "text",
success: function(rawData, status, xhr) {
var data;
try {
data = $...
9
votes
2
answers
5k
views
get dynamic properties in javascript [duplicate]
var tinymce_toolbar = {}
tinymce_toolbar.__default =
{
script_url: '/cms/libs/js/manual/renders/tiny_mce/tiny_mce.js',
};
tinymce_toolbar.__simple =
{
script_url: '/cms/libs/js/manual/renders/...
9
votes
1
answer
3k
views
Javascript equivalent to Ruby's `send` [duplicate]
Trying to loop on all updated field I've got and update them dynamically before saving.
Product.findOne({ _id: productNewData['_id'] }, function (err, doc) {
for (var key in productNewData) {
# ...
2
votes
3
answers
11k
views
Use Javascript variable in object name? [duplicate]
I am using CKEditor, and, when referring to the CKEditor instance, I need to use a variable. But, since calling the instance is a object, I am really not sure how to do this.
I am using:
CKEDITOR....
2
votes
2
answers
26k
views
javascript getProperty [duplicate]
I'm a complete beginner trying to learn Javascript. I am trying to complete a problem requiring me to return a value assigned to a key. The function is called getProperty and I am stuck - it keeps ...
4
votes
1
answer
7k
views
How to reference a collection name with "." in Mongo db? [duplicate]
I have a mongo DB, in the mongo shell, when I run "show collections", it returns the collection with dot in the collection name like
a.1
a.2
a.3
How I refer it in command like
db.a.1.find()
the ...
5
votes
1
answer
3k
views
Call function programmatically/"by string" in coffeescript [duplicate]
Possible Duplicate:
Dynamic object property name
I have a function that I need to call based on a user inputted data.
So for example, I have:
models.cat
models.dog
Now, I want to be able to call ...
5
votes
3
answers
5k
views
How to get object values with dynamic variable from json [duplicate]
I want to get the value of an object field from JSON. I have a dynamic variable let check_permission_key = 'ratingscalename'; and have one JSON
let overwrite_key = {
studentimage: 'student',
...