You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Don't forget about "square bracket notation"
The dot requires the key to be a valid variable identifier. That is: no spaces and other limitations.
There’s an alternative “square bracket notation” that works with any string:
constcar={wheels: 4,name: "minicooper",color: "pink",'Is this a good car?': true};car['Is this a good car?'];// true
With the brackets notation we can obtain the property name as the result of any expression:
constkey='name';consttype='car';car[key];// minicoopercar['Is this a good '+type+'?'];// true
const car = {
wheels: 4,
name: "minicooper",
color: "pink"
};
car.name;
// "minicooper"
The text was updated successfully, but these errors were encountered: