I try to push the rank value inside the array if it is not empty. But i cannot check the empty value.
Array Data
0: {name: 0, age: 58, dob: "", mark1: 63, mark2: 43}
1: " "
2: " "
3: " "
4: " "
5: " "
6: " "
if object is empty it should not enter into if loop,right now Loops enter into all the 6 objects.
for (let j = 0; j <= 6; j++)
{
if(rankData[j] !==undefined && rankData[j] !==" " && (Object.keys(rankData[j]).length)!== 0 &&
rankData[j] !=='undefined' && rankData[j] !=='undefined-undefined' )
{
rankData[j].rank = J;
}
}
If object is not empty is should push the rank value . But right now even object is empty it enter into if loop and show error in this line rankData[j].rank = J;
rank valuein your case? Check if the array has an empty string? It's hard to understand what you need, please reformulateifis run every time? (Also, you have a typo,raknData)rankData[j].rank = j;? Also, if you see errors, please include them in the question, they are generally the most important piece of information about a problem.