I have an array of both objects(JSX elements) and Strings. I want to iterate over the array and perform operations to the strings and skip the objects. What I have right now is this:
let arr = [...arrayOfStringAndObjects];
for (let i = 0; i < arr.length; i++) {
if (typeof arr[i] === "string") {
arr[i].replace(regexForKeywordSearch, (match: string) => {
return "123456789!@#$%^&*" + match + "123456789!@#$%^&*";
});
arr[i].split("123456789!@#$%^&*");
} else {
continue;
}
essentially I am trying to cut out a string based on a list of keywords and splitting them (which I will flatten later). However Typescript is not allowing me to perform string methods throwing me this error : "Property 'replace' does not exist on type 'string | object'. Property 'replace' does not exist on type 'object'."
How can I allow typescript to ignore when the type:object is encountered in my loop?