I'm trying to use normalize-url in my code here:
The socialfields is an object I converted to an array using the for...of loop. The value of the socialfields keys are URL to social medias
e.g:
{
youtube: 'youtube.com/peoray',
facebook: 'facebook.com/peoray',
twitter: 'twitter.com/peoray',
}
So I'm trying use normalize-url on the links. But it's not working. The error I'm getting is that TypeError: Cannot read property 'length' of undefined.
Here is the code:
for (const [key, value] of Object.entries(socialfields)) {
if (value.length > 0)
socialfields[key] = normalize(value, {
forceHttps: true
});
}
null. It means thevaluewill benullandnull.lengthis an Error.if (value.length > 0)- the following should be fine:if (value)or if you really wantedif (value && value.length > 0)- this is happening because the.lengthproperty does not exist on a null object/variable.socialfieldsobject right before the for loop. My guess is that you have an entry like thispinterest: nullif (value)not clean enough? That's all you need....