i have checked the node list before adding the 'fetchValues' function to make sure that it have a value , but when i add the function , this error shows up: Uncaught TypeError: Cannot read properties of undefined (reading 'value')
i dont understand why the code runs with no issues and the opposet when i add the function ?
const fetchValues = (attrs, ...nodeLists) => {
let elemsAttrCount = nodeLists.length;
let elemsDataCount = nodeLists[0].length;
let tempDataArr = [];
//first loop deals with the no of repeaters value
for(let i = 0; i<elemsDataCount; i++ ){
let dataObj = {}; // creating an empty obj to fill the data
//second loop feletej th0eajh<eelemeaters value or attributes
for (let j = 0; j < elemsAttrCount; i++ ) {
// setting the key name for the obj and fill it with data
dataObj ['${attrs[j]}'] = nodeLists[j][i].value;
}
tempDataArr.push(dataObj);
}
return tempDataArr;
}
and here is the code when a checked it , before and after the function :
// before
let acheivementsTitleElem = document.querySelectorAll('.acheiv-title'),
acheivementsDescriptionElem = document.querySelectorAll('.acheiv-description');
console.log(acheivementsTitleElem,acheivementsDescriptionElem);
// after
let acheivementsTitleElem = document.querySelectorAll('.acheiv-title'),
acheivementsDescriptionElem = document.querySelectorAll('.acheiv-description');
console.log(fetchValues(['acheiv-title','acheiv-description'],acheivementsTitleElem,acheivementsDescriptionElem));
i tried to understand it but i didn't find any logic reason of not finding the value of the node list
['${attrs[j]}']
should be[attrs[j]]
nodeLists
aren't all the same length. You'll get that error if any of them are shorter thannodeLists[0]
.console.log(acheivementsTitleElem.length, acheivementsDescriptionElem.length)
show?