I’ve an array of objects: I want to compare the objects within an array by name. If the duplicate name exists, I should compare the age and only keep the higher age object. The expected output should be: I am new to javascript/typescript and couldn’t find any optimal solution for this problem. I h…
Tag: arrays
How to get the same value from 2 different arrays
Hi! There are two different arrays and I want to compare two arrays and find the id of selected animals from the zoo. How do I get the array of ids? Also, the id has to be a string. Thank you Answer Make a look-up table that gives the ID for each name, then use this to get the IDs
Why my array resets itself when I leave my function?
I come here after two whole days without success. I want to increment my array with the pictures selected by the User, for return to my database a list of uri. But when the user choosed the first picture and re-open the android navigator for take a new picture, I saw the array doesn’t increment. It take…
How do arrange arrays with different combinations?
I have 3 arrays [“s”,”m”], [“Red”,”Black”], [“1”, “2”]. I want to arrange them like this: I’m out of idea, please help me. Answer Loop each one then just combine them into an array. Script: Output:
How to find the next position in a 2D array based on the current position? [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 10 months ago. Improve this question Suppose I have an array with 3 rows and 4 columns const arr = [[1,2,3,4]…
Adding data to an array and accessing the data inside the array outside the function Javascript
I’m new to Javascript and I’m not understanding how to persist data in an array. In my function I’m reading a file line by line and saving it in an array. I figured that because the array is declared outside the function that data would remain in it, but that’s not what happens. I woul…
Match variable value to array’s index to get month
I’m trying to turn my YYYY-MM-DD string date format to a DD mon, YYYY string. I was thinking about using an array with the months and matching the month number to it’s index, but I can’t find a way to do so. Answer You just need to pass the month – 1 on your array. It should return the…
How do you group an array by n and the number of decreasing integers (n-1)? With the output to be the total number of arrays
For example, this is the input array: [2, 1, 4, 4, 3] From this array, n-1 patterns will be established from left to right. This output would be the number 7 because the following separate arrays exist after grouping: [2] [1] [4] [4] [3] – 1 group (n) [4, 3] – 1 group (n-1) [2, 1] – 1 group …
iterate through array in javascript and return in new array
i’m totally new to coding: i want to iterate through the array input, select the positive numbers only, then put them in a new array liste and then print the new array in the console. what am i doing wrong here?!? Answer I’ll attempt to combine the points made in several other answers here, and ad…
How to import an useState object from another folder
I have a project which created in “Creat React App” and i have an useState array which looks like this: This array is in another folder inside a component called StateComp, but i also want to load this array in the main folder (App.js for this case). I tried to just import the State and the setSta…