Fieldset » element

element(name) → element or null
element(name, options) → element or null

Retrieve a single entry as Field (instead of its direct value) from the fieldset by its name. Optionally specify whether it's optional or mandatory for the entry to be present in the eno document (by default it's optional).

enoyears:
2007 = Year of the gooseberry
2010 = Year of the awesome beanstalk
2011 = Year of yearning
javascriptconst fieldset = eno.parse(input).fieldset('years');

fieldset.element('2010');  // returns [object Field name="2010" value="Year of the awesome beanstalk"]
fieldset.element('2020');  // returns null
fieldset.element('2020', { enforceElement: true });  // raises an error
fieldset.element('2020', { required: true });  // raises an error

Parameters

name

The name of the entry to fetch from the fieldset as a string.

options

enforceElement

Whether the element must be present in the document (true or false, defaults to false)

required

Alias for enforceElement (this exists on many methods and depending on context refers to either element or value)

Return value

An element (e.g. Field, List, etc.) or null.