How do I find out where an ID already exisits when assigning an Object property?

Asked by Sarah Saunders

I am trying to assign in ID (object properties) but it keeps giving me an error that the ID already exists. But I can't find it anywhere. Help.

Question information

Language:
English Edit question
Status:
Solved
For:
Inkscape Edit question
Assignee:
No assignee Edit question
Solved by:
Hachmann
Solved:
Last query:
Last reply:
Revision history for this message
azra (alveera5978) said :
#1

const
    array = [{ taxonomy: 'category', id: [ 10, 100 ] }, { taxonomy: 'post_tag', id: [ 20 ] }];
    object = { taxonomy: 'category', id: 30 },
    item = array.find(({ taxonomy }) => object.taxonomy === taxonomy);

if (item) {
    item.id.push(object.id);
} else {
    array.push(Object.assign({}, object, { id: [object.id] }));
}

console.log(array);

   // remove the last insert
   // find item with taxonomy and id
   item = array.find(({ taxonomy, id }) => object.taxonomy === taxonomy && id.includes(object.id));

// remove from id by using the index
if (item) item.id.splice(item.id.indexOf(object.id), 1);

console.log(array);

Revision history for this message
Best Hachmann (marenhachmann) said :
#2

Hi Sarah,

please ignore the spam above.

You can search for any value in the Search + Replace dialog (Edit > Find / Replace or Ctrl+F).

Revision history for this message
Sarah Saunders (ssaunders11) said :
#3

Thanks Hachmann, that solved my question.