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:

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

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

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

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

current.labels.assert( "maynotexist" )

and if you assign a label with

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.

Gabriel illescas Cavazos avatar image Gabriel illescas Cavazos commented ·

I want to set this condition for example if any label exist do nothing but if the label doesnt exist do something how can I do it?

0 Likes 0 ·
Jacob Gillespie avatar image Jacob Gillespie ♦ Gabriel illescas Cavazos commented ·
@Gabriel illescas Cavazos
if(!obj.MyLabel? && obj.MyLabel? != 0) {
    // Label not set
    // Do Something
}
0 Likes 0 ·
Gabriel illescas Cavazos avatar image Gabriel illescas Cavazos commented ·

what does it mean "!" when you star the if?

0 Likes 0 ·
Matthew Gillespie avatar image Matthew Gillespie ♦♦ Gabriel illescas Cavazos commented ·

A "!" is a logical not.

This will return true only for strings that start with h:

text.startsWith("h")

This will return true for any string that starts with any letter other than h:

!text.startsWith("h")
0 Likes 0 ·
Vedant G avatar image Vedant G commented ·

I tried the ? method but it doesn't work for me

0 Likes 0 ·
capture.png (93.9 KiB)
capture-2.png (16.1 KiB)