Why is there a companies.filter is not a function error?

I import a list of companies and internships in the backend as shown:

{
    "companies": [
        {
            "companyID": 1,
            ...
            
        }
    ],
    "internships": [
        {
            "internshipID": 1,
            ...
        }
    ]
}

Btw this is saved as companies:
const [companies, setCompanies] = useState([])

I then use this code to filter through the arrays when someone searches for a specific one (just for companies):

const companiesArray = companies["companies"]

const filteredCompanies = companiesArray.filter(company =>
    company[searchBy]?.toLowerCase().includes(searchTerm.toLowerCase())
);
console.log('Filtered Companies:', filteredCompanies)

I then get the error that companies.filter isnt a function and im not sure why

Since companies is an array, so i thought this should work. What should i try?