I need to filter and sort a nested tree object for menu so is sort and filter status === true ,How to turn to Answer I would write two recursive functions: One to filter out the status: false items One to sort items by their sort property You can combine the two in any order you like. itemFilter The filter
Tag: arrays
creating alt tags for images gotten through JSON
This web page has three cards with information above and an image below. I am using JavaScript and HTML to get the information that goes to my web page. My JavaScript gets the information it needs from the following online JSON file. The file doesn’t contain alt text for the image. when I run the Wave e…
scrollToIndex out of range: request index1 but maximum is -1 .. React Native
when I run my application it’s okay and work If I create an array and put it in the data in FlatList like this array But when I replace the photos array with an API, The app doesn’t work. I tried more than API, I think the error is in my code not in the API, This error appears to
How can I remove a specific index from an array and then insert a new one on that same index?
I am trying to do one thing but I have 2 choices Remove a specific item/index from an array and then insert a new one in that same index. Do not remove the item but edit it with new data. I have this piece of code: It removes the item from the array, but when it adds the new item,
How to concataecance object array values of duplicates
I have an object that contains duplicate id properties and I want to reduce them to one array for each. I only figured out a way to find unique ids, but how can I concat the name attribute? Desired result: Answer Simple reduce to combine and using Object.values to get the result you are after.
My replace function works with array but not with HTML collection which is also an array. Why?
I am writting a function to replace the position of some HTML elements in the page. Should be simple and it goes like this : It works with testArray but it doesn’t seem to have any effect on the HTML elements order. Why and what can I do to change the original DOM? Answer You need to clear the element&#…
How to dynamicly access a object and then edit its content [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 1 year ago. Improve this question So i have for example such an object: And now i want to dynamicly acess it,…
How can I convert an indexed JavaScript object to an array of objects?
I have an object that looks like this: I’m trying to convert it into an array of objects so I can do obj.map((obj, idx)=>{//display obj.price and obj.serialNumber//}), so I want to convert obj into an array like this: I initially used array = Object.values(obj[‘serialNumber’]) to just get…
push even and odd numbers to respective arrays using a for loop
I’m a total beginner and I’m stuck completely on this problem. I’m supposed to use a for loop to traverse an array, pushing odd numbers to the ‘odd’ array, and evens to the ‘even’ array. No numbers are showing up in my arrays when I test the code. I’ve tried wri…
how do i copy an array correctly
im trying to make a copy of an array but when i change the copy it also changes the original. i have tried using Object.assign([], scenes), scenes.clone() and tried using a for loop Answer You can also try const arrayCopy = JSON.parse(JSON.stringify(initialArray)), although the method using the spread operato…