In theory it should transform a given array to camel case. I don’t understand what is wrong Answer The .replace() method doesn’t modify the word variable, it instead returns a new modified string. So your code is producing new values within the loop but doesn’t do anything with those values.…
Tag: arrays
Comparing two nested arrays of objects, and exclude the elements who match values by “id” into new array in JS
I have two arrays of objects, i need to match arr2 names to arr1 by matching id’s Answer You could create a Map from arr2, keyed by id and with as value the corresponding object. Then map arr1, looking up the object in the Map, both for the object itself and the children:
Filter an array nested within an object
I was able to find many sources saying how to filter nested arrays, but all of these referred to arrays within arrays. In my case, there’s an array nested within an object and I can’t figure out how to deal with it. The source array is: How to filter the nested array so that the resulting object l…
Getting all the children of a tree javascript object as a flat array
I have a tree-based javascript object. So, im trying to get all of them as a flat array, like this: What options do i have to get them all without doing some dirty spaguetti code? I tried using array.forEach() but it naturally requires doing another iteration inside it, and surely will require it again while …
Reduce nested array maximum values to a single array
I am trying to find a way to reduce the max values of specific positions/indexes within nested arrays into a single array. Given: const myArr = [[105,87,171],[113,192,87],[113,87,87],[113,87,87]] Expected return value: [113,192,171] Actual return value: [113,87,87] Using the following code, I’m getting …
How to remove the lower values in a list of object arrays in js
I want to keep the highest bitrate for each type of quality, so 1080p will keep the one with itag 137, and 720p will keep the itag with 398. Here is my list with object arrays Answer You can use the Array.prototype.reduce() Method to reduce an array by iterating all items and returning the outgoing result. In…
data grouping based on key value in javascript?
Hi I am having an array of values like this Input By using the below function I am converting the data into the format like this – https://codesandbox.io/s/tanstack-table-expansion-1t77ks?file=/src/data/table-data.json:0-9490. Which is then used in the @tastack-react-table. You can see the demo of the a…
How can I can keep the done Todo’s from vanishing
I am trying to create a Todo list and wonder how I would go about keeping the completed todos from vanishing each time I add a new task. I am aware that this is happening because I clear my div each time a new task is added, however I am unsure on how to proceed for me to keep using
How to insert an array to another array at each iteration of a for loop in javascript
I have a function to bubble sort and I want to save the array after each swap into another array. The bubble sort is working properly and I can log the array after each swap to the console. But I cant seem to push to the other array properly. Here’s my code : Here’s a screenshot of the console :
How do I get the index of two variables, compare them, and return true or false
I am making a trivia game that uses an array of objects. I think the correct way is to get the index of the correct answer by using .find, getting the the index of the selected answer, then use an if statement to compare the two. If they match then the console will log “correct” or “incorrec…