Skip to content

Tag: arrays

Filter array of objects with available or not filters

Suppose I have this dataset: and I want to filter it by some values, for example by animal and by year. Very easy I can do: same here: My problem is that sometimes animal or year can be null. In that case I want not to filter by that value. For example these are what I would like to obtain:

javascript add up date and time object in an array

so I have a list of array of time and date I want to join both appointmateDate and appointmentTime to iso format and get a new array of timeRange is that possible🙏🏻 Answer Using setHours. Loop over the array using Array#map and create a new Date object using appointmentDate and then using setHours and appoint…

Ignore $in if empty array is provided

I have the following model: Note: interface matches the model exactly but i pasted this as its much shorter. I am using the following data to filter through this collection: What i want to achieve is to find every document and check if the corresponding array has at least one of the values from the array i se…

Array.from() not converting nodeList into an array

I’ve created a nodeList of list elements using createElement(). Then I’ve used Array.from() to convert the nodeList in question into array I can iterate over. I want to apply a different width according to the value of the index. If index is even width of 300px else width of 500px. However, the co…

Returning array values, not the array iterator in Javascript

How can I return the values of an array? The methods .values() and .entries() seem to return an Array Iterator. This is not what I want. I am also not allowed to modify func1() function for this edge case. Thanks! Answer As Bergi stated, func1() will always return an array, no matter what func2() returns. But…