I’m facing an issue with my JavaScript code. When I attempt to execute a function named dodajKorisnika, I encounter an error message stating korisnici.push is not a function. I suspect the issue relates to my array management, but I can’t identify the exact problem. This function is designed to append new items to my array, yet it consistently produces this error whenever I invoke it. Has anyone experienced this before? Any help or advice to resolve this would be greatly appreciated. Thank you in advance!
Had this exact error last month working on a user management system. In my case, I’d declared the variable but never actually initialized it as an array. You might have let korisnici; somewhere without the = [] part, leaving it undefined. I’ve also hit this with async operations - if you’re pushing before your data loads, the variable’s still in a weird state. Double-check your initialization order and make sure you’re not using the array before it’s set up. Also watch for scoping issues where you think you’re using one variable but you’re actually hitting a different one with the same name.
maybe you set korisnici to something else by accident? double-check if you’re not assigning it a different value. it’s a common mistake, i do it too sometimes haha.
This happens when korisnici isn’t actually an array when you’re trying to push to it. Double-check that you’re declaring it as let korisnici = []; or var korisnici = [];. You might also be reassigning it somewhere else in your code to a string or object instead of keeping it as an array. I’ve been there - accidentally overwrote my array with an API response that returned an object. Try console.log(typeof korisnici) and console.log(Array.isArray(korisnici)) right before your push call to see what you’re actually working with.