Skip to content

Tag: javascript

Mapping arrays into object with values as an array

I would like to create an object containing all the values from the array first and the values from second as an array of values, assuming that this key references multiple numbers such that given the arrays: This is what I have tried: This is what I get: Answer This is the easiest method to understand as it&…

Filter array of infinitely nested objects

Let’s say I have an array of nested objects such as: And I would like to return a new array with id: 3 excluded for example. So it would become: The excluded id can be from any level, and it and its children should be removed. What’s the best approach to do this? I’ve tried several other sol…

How do I add multiple tables without writing them 1 by 1

I try to find small real life problems and attempt to write code to make my life easier, one of them being a search-table simple program that sorts data based on user input. And my question is, is there a more efficient way to import data rather than having to write. like 1000 times? I would appreciate guidan…

JavaScript remove class from table rows

I have a table that highlight the tr (row) on click, and I can highlight multi rows on every click but I want to have only one row to be highlight in table. how to remove the highlight class from sibling rows. code below JavScript css Answer I ended up adding below code and issue resolved.

Not being able to print an array

i created empty array using the React State Hook, the array starts empty and i have 3 functions to (add to the array), (remove the last element of the array) and another to empty the array. The functions seems to work since i logged the result in the console. But when i want to print the array on a paragraph,