How to access or update entity properties in the PropertyBag

I’ve added a property to an entity with viewer.selectedEntity.properties.addEntity("myPropertyName", true) but how do I

  1. choose this particular property by name when using the getValue() method?
  2. update the value of that specific property later?

I can’t find any code examples of this. And the docs aren’t clear to me on it either.

Any time I try to access entity.properties it says that properties is undefined. So it will not let me add a property using the method there.

If I use entity.addProperty("myPropertyName") I can’t figure out how to access it, either.

You can access the property by the property name. For example:

var blueEllipsoid = viewer.entities.add({
  name: "Blue ellipsoid",
  position: Cesium.Cartesian3.fromDegrees(-114.0, 40.0, 300000.0),
  ellipsoid: {
    radii: new Cesium.Cartesian3(200000.0, 200000.0, 300000.0),
    material: Cesium.Color.BLUE,
  },
});

blueEllipsoid.addProperty('age');
blueEllipsoid.age = 11;
console.log(blueEllipsoid.age);

The code above will print out 11 as the value for blueEllipsoid's age.