let $object= [
{
tagName: "01",
contentID: [100, 200],
occurrences: 2
},
{
tagName: "02",
contentID: [200, 300],
occurrences: 2
},
{
tagName: "03",
contentID: [100, 200, 300],
occurrences: 3
},
{
tagName: "04",
contentID: [300],
occurrences: 1
}];
Я хочу увеличить значение occurrences
, когда tagName
соответствует.Как мне увеличить occurrences
значение / количество?
// let tagManagerArr = [];
// global scope
for (let content of contents) {
contentId = content.contentID;
entityType = content.entityType;
let tags = content.tags,
check = false;//check gives me whether a tagName is already present in the '$object' array..
for (let tagName of tags) {
console.log("---------------------------------------")
tagManagerArr.forEach(
(arrayItem) => {
if (arrayItem.tagName === tag) {
check = true;
}
}
);
//tagManagerArr.find(
// (element) => {
// if (element.tagName === tagName) {
// check = true;
// }
// });
if (!check) {
tagObject = {};
tagObject['tagName'] = tagName;
tagObject['contentID'] = [];
tagObject['occurrences'] = 1;
tagObject['contentID'].push(contentId);
} else {
tagManagerArr.find(
(element) => {
if (element.tagName === tagName) {
if (!element.contentID.includes(contentId)) {
element.contentID.push(contentId);
}
element.occurrences += 1;
}
});
}
tagManagerArr.push(tagObject);
}
}
это работает нормально, но с неправильными вхождениями .. Любая подсказка?