Getting UUIDs from an array

#1

I would like to create an action where by tagging a draft “quick entry” it can be used in a menu.

Line 1 is giving me an array of the tagged drafts, But I need to turn that into an array of the UUIDs of those drafts. What am I doing wrong? (I’m sure lots of things! Still learning…)

var options = Draft.query("", “inbox”, [“quick entry”]);
options = options.uuid
alert (options)

While we’re at it, I’m going to need to get at other data for the drafts - first line, etc. so they will pop up in the menu by “title”

0 Likes

#2

There are a couple of ways to get properties from objects in an array in Javascript. The map function is easy if you are grabbing values, like:

let drafts = Draft.query("", “inbox”, [“quick entry”]);
let uuids = drafts.map(item => {
    item.uuid;
});
// now uuids is an array of just the UUIDs of the drafts.

If you need multiple values, it can make sense to loop over the items in the array of drafts as well, like:

let drafts = Draft.query("", “inbox”, [“quick entry”]);
let uuids = [];
let titles = [];
for (let draft of drafts) {
    uuids.push(draft.uuid); // add uuid to array
    titles.push(draft.title); // add title to array
}
// now uuids is an array of uuids
// and titles is an array of the titles
1 Like