New struct function: struct.has()

Javascript utility libraries underscore and lodash both have the nice short syntax _.has(object, “key”) which is shorter than StructKeyExists or struct.keyExists() or javascript’s verbose hasOwnProperty()

struct.has(string|list|array|struct,delimiters)

Could we add struct.has(string|array|struct, delimiters) to Lucee? not just an alias for keyExists but with
the extra option of checking for the presence of multiple keys. i.e, either from a list, an array or does this struct contain call the keys of this other struct?

(this forum software is a bit pedantic about titles being a “proper sentence”, I wanted to include the code sample in the title, but it wouldn’t let me post)

2 Likes

I’ve been doing this with my beans for years by implementing a generic has( "property" ) method in my base cfc

Would love to see it in the language for structs. I use struct.KeyExists() constantly and though it’s an improvement over StructKeyExists( struct, "key" ), struct.has( "key" ) is even clearer.

1 Like

the docs will have member functions as soon as somebody figures out why content changes
aren’t being pushed out from the automated build process