Message 1 of 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Solved! Go to Solution.
Solved! Go to Solution.
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.
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?
if(!obj.MyLabel? && obj.MyLabel? != 0) {
// Label not set
// Do Something
}
what does it mean "!" when you star the if?
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")
