So i have an array of objects named: tokens. Each object from this array has this format: {tokenName: string}. I want to test if each element from this array has the exact same format or else throw an error.
I have tried this:
for (let i = 0; i < tokens.length; i++) {
if (
typeof tokens[i].tokenName === "string" &&
tokens[i].hasOwnProperty("tokenName")
) {
// do stuff
} else {
throw new Error("Invalid array format");
}
But it won't pass the test.