Section » element

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

Retrieve a single element of any allowed type from the section by its name. Optionally specify whether it's optional or mandatory for the element to be present in the eno document (by default it's optional).

enotitle: Artfest 2018
tags:
- art
- code

# content
> ...
javascriptconst document = eno.parse(input);

document.element('title');  // returns [object Field name="title" value="Artfest 2018"]
document.element('tags');  // returns [object List name="tags" items=2]
document.element('content');  // returns [object Section name="content" items=14]

document.element('fantasy');  // returns null
document.element('fantasy', { enforceElement: true });  // throws an error
document.element('fantasy', { required: true });  // throws an error

Parameters

name

The name of the element to fetch from the section 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. List, Field, etc.) or null.