Uncaught TypeError: data.forEach is not a function at XMLHttpRequest.request.onload
The data at the URL https://restcountries.eu/rest/v2/alpha/col
is not an array, it is a JavaScript object. If you want to traverse it's properties with forEach you have to call something like Object.keys
or Array.from
on the parsed data, like
Object.keys(data).forEach((k) => {
arr.push(data[k].name)
})
res.data.forEach is not a function in Jquery
Ah, I just realised. Look at your res.data
and you need res.data.data
. Replace your code with:
let totalData = [];
let monthData = [];
$(async function () {
await axios.get(`/dashboard/chart/month`).then((res) => {
console.log(res.data);
// Add another data here:
res.data.data.forEach((data) => {
totalData.push(data.total);
monthData.push(data.months);
});
});
});
The res.data
is the Axios's version. It has your data + status and other stuff. You have your data
as well. So you need res.data.data
.
Related Topics
How to Disable Onclick Without Altering Its Function
How to Redirect Drop Down Menu When Option Is Selected
Dynamically Increase and Decrease an Input Text Box Size Depending on Another Selector Width
Regex to Get String Between Curly Braces
How to Delete a Localstorage Item When the Browser Window/Tab Is Closed
Group By, and Sum, and Generate an Object for Each Array in JavaScript
How to Change the Font Color, Font Size, and Button Color in React
Creating a Leaderboard in Html/Js
How to Trigger Change of Option in Dropdown When Options Can Have Same Value
Trigger Event When Element Becomes Visible With Ngif
How to Share and Edit Global Variables Between Two JavaScript Node Runs
React Native Dynamically Change View's Background Color
How to Force Clients to Refresh JavaScript Files
How to Disable Clicking Inside Div
Javascript - Adding White Space to Left of String
Pause/Stop Videos into Tabs When I Clicked on a Tab
Reactjs - How to Update Nested and "Normal" State Properties