Checking for dupe entries given user input

Is there a best practice method, when taking input from a user (say picking from a list of items) to check if that item has already been chosen (the set of chosen things being in an apexDataArray?
Typescript has a bunch of examples of eliminating duplicates, but say you want to catch the user trying to add a duplicate?
A better way of course would be to filter the list of options by what was already selected, but we can ask that separately.

For example, have a list of options in a component, passed in by the owning UI page:
links → apexDataArray
And we have an AutoComplete serving up a bunch of business object values:

this.topics.setOption('where', where);
await this.topics.read();

and when something is chosen in the AutoComplete, we have a ‘add’ method being driven and add to the list:
const newLink = await this.links.add({ childTopicId: value.id });

But we want to check if the thing chosen (value which is an object in the example above) is already in the set of ‘links’ that were passed in (and where we’re maintaining our set of items)

Perhaps something like:
if (this.links.find((obj) => obj.childTopicId === value.id)) throw ???;

Your first comment is the best approach - filter the list so that the user cannot select something that they have already created.

You could also explore a unique index on the business object that would prevent creating the duplicate but the error message from that is pretty technical.

You could also add a before create event handler server side that checks for uniqueness before trying to create it and throw an error message if it already exists.

and in terms of filtering the list with things already chosen…if the selected items are held in a apexDataArray (or some other data structure that has the objects), would we just set up the read() filter to exclude those entries through creating text for the filter using something like the ninq phrase? Or some more sophisticated way of linking the result with the objects held?

If you are filtering server side using a where clause option and read, you are correct. You would use nin (not in) filter like this:

{
  where: {
    propertyName: {
      nin: ['value1', 'value2', 'value3']
    }
  }
}

If you are filtering client-side, you could use the .filter method on the array in memory.