Skip to content

Tag: arrays

Get value from array key and build a new array

I cannot get the value of ‘Date’ key to build my array. The console shows this output: Seems like the problem is with Object.keys(o)[0]. How can I fix this? Answer You actually want the first value, not the first key. However, since you already know the name of the key, you can simply use o.Date.

Array of products arrange by category

I’m trying to arrange this array of products by categories. For now, I get the count of each category but I can’t figure out how to make this two dimension array output. This is my code for now: Answer You can group elements by reducing over the array using an object to store elements belonging to…

Filter nested obejct

So I have this function that in theory should filter an array of movies by a given genre, but i get this error: Am I doing this stuff right or did i mess up one of the functions? Any help would be very much appreciated! edit: here’s an example of a movie object Answer as some comments suggested, i was

Write nested map function

I have an object like this: Expected output : And I already wrote a function like this: I can write another function to flatten the output of the code above, but is there any other way to write the code above into a more general function (not hardcoded) that can apply to any object? Answer You can use a recur…