I try to do the following:
var properties = ["height" , "width"];
for (var prop in properties){
div.style[prop] = otherdiv.style[prop];
}
But dart doesn't seem to accept this bracket notation, is there any other way to access a property using a string in dart ?
For general Dart objects, there is no way to access properties from a computed name. That's a deliberate language choice - it makes it possible to optimize object layout differently when it doesn't have to allow unpredictable access.
To access the object property dynamically in JS, you need to pass the property name as a string in square brackets. As the value of the variable key changed, we got access to the different properties of the user object. The most common way to access the object properties in JavaScript is the dot.
You can use the getPropertyValue
and setProperty
methods like
div.style.setProperty(prop, otherdiv.style.getPropertyValue(prop));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With