You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Lesson 18: orders.js:5 Uncaught (in promise) TypeError: orders.unshift is not a function #180
Never mind, fixed it after console logging type of order. It was stored as string not as array. heres the fix :
first i removed local storage of orders with - localStorage.removeItem('orders');
and then changed orders.js to:
export const orders = JSON.parse(localStorage.getItem('orders')) || [];
export function addOrder(order) {
orders.unshift(order);
saveToStorage();
}
function saveToStorage() {
localStorage.setItem('orders', JSON.stringify([orders]));
}
Activity
yeugi322 commentedon Jan 18, 2026
Never mind, fixed it after console logging type of order. It was stored as string not as array. heres the fix :
first i removed local storage of orders with - localStorage.removeItem('orders');
and then changed orders.js to:
export const orders = JSON.parse(localStorage.getItem('orders')) || [];
export function addOrder(order) {
orders.unshift(order);
saveToStorage();
}
function saveToStorage() {
localStorage.setItem('orders', JSON.stringify([orders]));
}