question

Gabriel illescas Cavazos avatar image
0 Likes"
Gabriel illescas Cavazos asked Steven Hamoen edited

which command return if label doesnt exist in item?

labelslabelexists
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Mischa Spelt avatar image
2 Likes"
Mischa Spelt answered Vedant G commented

If you want to know whether the label exists and has a "truthy" value, you can use the question mark:

  1. if(current.maynotexist?) {
  2. // current.maynotexist exists and is non-zero, or points at a valid object
  3. }

If you just want to know if it exists, you can do

  1. treenode maynotexist = current.labels["maynotexist"];
  2. if( maynotexist ) {
  3. // the node exists, get its value with maynotexist.value
  4. }

However, you don't need the latter construction very often, for example, if you want to create the label if it does not exist, you can

  1. current.labels.assert( "maynotexist" )

and if you assign a label with

  1. current.maynotexist = 1;

it will be automatically created.

· 5
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.