Skip to content

Tag: arrays

Get array’s depth in JavaScript

In order to get the array’s depth I thought I can use the flat() method like so: It seams it works BUT if one of the arrays inside has a length of 1 let testRy = [1, 2, [3, 4, [5, 6], 7, [8, [9] ], 10], 11, 12] the function fails since the flattened array is as long as

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…

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…

How can I conditionally format my HTML table?

I have a HTML table like above I’m trying to do conditional formatting based on the formula applied on the numbers there I tried this: I could not get those values Any modifications or suggestions are appreciated Thank you Answer the only problem with your code is you are using wrong js context to searc…

Vue filter array A by array B

I have a table with data from a rest API. The table has objects with unique ids and I have a group filter with unique group ids. The group id does not appear in the table, therefore I have to create an array which only contains the ids of the table objects. Every time the group changes the array will

Create object from another one using filter function

I’m trying to create an array of objects using an array of objects. My first array is like that : And I want to create an object list with only an id, a name and a task. This is what i do actually, but it doesn’t work : The ListModel object is : Answer The filter() function is more-so utilized