Skip to content

Tag: javascript

Vue How to Merge Two Arrays From Same Object?

I am pulling data from an API that gives me an object of items, each containing a string named correct_answer and an array named incorrect_answers. I am trying to combine those values within each item, so when I do v-for, it will loop through the answers merged together in one loop. I also want to randomize t…

Cannot Read Property ‘update’ of undefined

The Chest Objects i’ve created have an update function, but apparently they dont exist or are not declared? I feel like ive been pretty thourough checking my work, but it’s pretty complicated and possibly above me and have no idea whats wrong, my code is commented so as to make your job easier sin…

How to select all elements with a class in JS

I’d like to modify all classes with JS. Is there way to select them without manually setting the array index (for example [0] or [1] or [184])? Example code: It works only when I add [0] and only for the first element that has the class. But I’d like to modify all the elements with the class. Answ…

create-react-app always throws babel error

Every time I create a create-react-app project it throws this error: I have tried downgrading to 8.0.4, I’ve tried installing 8.0.5 I’ve even made sure all my dependencies for babel rely on a 8.0.5! I have no idea what to do from here as the error persists for every create react app I now build! T…

Splitting an array in equal parts

I am looking for a Javascript Algorithm to split an array into chunks, but avoiding any small left overs. For example: But I want this: So basically the output is spread over several arrays with a maximum number of elements passed in as second argument. Answer You should recalculate the size, which might need…

Iterating over keys instead of values Vue app

I’m trying to select the values for three keys from my api with axios. Each time I make a request I’m displaying the values four times for each key. I dropped a key from my data models and I re tested. When I did that my request displayed three times instead of four. Meaning I’m iterating ov…