Sentence in javascript but variable [duplicate] - javascript

This question already has answers here:
Accessing an object property with a dynamically-computed name
(19 answers)
Closed 6 years ago.
i'm working with titanium and alloy.
I need run a JavaScript sentence like
$.D7F15.visible="true";
but D7F15 must be a variable, like
var mifranja="D7F15";
How i can run this??
some help please??

You can use bracket notation to access object property
var mifranja="D7F15";
$[mifranja].visible="true";

Related

JavaScript object like String literal doesn't to set property [duplicate]

This question already has answers here:
Add a property to a JavaScript object using a variable as the name? [duplicate]
(14 answers)
How to create an object property from a variable value in JavaScript? [duplicate]
(9 answers)
JavaScript object: access variable property by name as string [duplicate]
(3 answers)
Closed 2 years ago.
In JavaScript everything is object like String literal, numbers, Object...
And properties can be added to objects dynamically also, but I am adding property to object which refer to string then it seems it is not working
Following is JS code which I am running
var aVar = "some string";
console.log(aVar);
aVar.name = 'raj';
console.log(aVar.name);
Output...
hi
some string
undefined

how to access property with hyphen in name in JS JSON [duplicate]

This question already has answers here:
JavaScript property access: dot notation vs. brackets?
(17 answers)
Closed 2 years ago.
Im trying to access an element in JSON With Hyphen in the property name
id("main").textContent = jsonData.res.main-result;
but that is causing an error
const json = {
'property-name': 'something'
}
console.log(json['property-name']);
Use jsonData.res['main-result']

How to Reference an Object's Property by a String? [duplicate]

This question already has answers here:
Accessing an object property with a dynamically-computed name
(19 answers)
Closed 5 years ago.
I have seen other questions asked on Stack Overflow about doing this, but I felt that they weren't answering the right question. They always answered how to access the name of an object with a string. However, I want to know a way to do this:
var obj = {
property: "hello!"
}
console.log(obj."property");//want it to log hello!
You just access it like it's an array index, so:
console.log(obj["property"]);

How to access object property as a string in javascript [duplicate]

This question already has answers here:
Accessing an object property with a dynamically-computed name
(19 answers)
Access JSON or JS property using string
(4 answers)
Closed 6 years ago.
I can do var foobar = foo.barto access the bar variable.
How would I do this if I had an arbitrary string that told me what element I needed to access. foo."bar" doesn't work.
I think
foo["bar"]
is the syntax you need

How to add/remove properties to object in runtime in javascript [duplicate]

This question already has answers here:
Adding elements to object
(19 answers)
Closed 6 years ago.
I would like to know how to add/ remove properties to object at run time in javascript? How to achieve this in javascript ?
Let's say your object is myobj
then you can add a member like this
myobj.myvar = value; or myobj["myvar"] = value;
and remove it with
delete myobj.myvar; or delete myobj["myvar"];

Categories

Resources