I have this program that involves entering your information and after clicking submit the information is then pushed to an array and send to console… the user can then search such as last name and if it has a match then it will show the other information that came with it after submit e.g. age,sex,birth…
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…
Create an array using forEach that has all the usernames
This is an array and I want to use foreach to create an array using forEach that has all the usernames with a “!” to each of the usernames What i try in JS: What i got in error: Uncaught SyntaxError: Unexpected token . What is the right way to use foreach to access the object in the array? Answer
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
javascript function returning day of week x num of days later
What I am trying to write is a simple function that takes in a day (D), X number of days and returns the day X days later. Days can be represented by (‘Mon’, ‘Tue’, ‘Wed’, ‘Thu’,’Fri’,’Sat’,’Sun’). X can be any int 0 and up. F…
JS Array.prototype.filter with Array extending class constructor call
I have a Array extending class A which I want to filter. It seems like the constructor gets called another time with just 0 as parameter. Why is that? Here is an example showing the problem: Which logs: Where is the 0 comming from? Answer Array.prototype.filter is returning a new (array) value. That value nee…
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