I am learning JavaScript right now and I want to practice for loops and if statements. So I found a little exercise: Remove all duplicates in the array. I know there a probably better solutions but I want to know why my code isn’t working. Can someone help me? Thx 🙂 Answer splice is a method so you have…
Tag: arrays
how can i refactor this function using array destructuring?
Helo everybody, I have build this function to convert the fetch data of an Api to an array of objects, but linters are requesting me to use array destructuring. can jou please help me? im just a begginner so please be nice! Answer Ignore that particular warning message. But still you should fix some things in…
Overwrite array object if already present else add to array
When I run this example I expect the elementThatAllreadyExist to overwrite the existing object with the name test1 which it does correctly. When I run the example with arr2, I expect the newElement element to be added to the array since no object with the name “test33” exists in the array, but no …
why is the following code not returning sum of all the array elements?
Below is the code, I want to return the sum of all the array elements, why is it not working. I know we don’t need the Promise to achieve that but I would like to know how it can be done with a Promise. output:[object Promise]8 Answer I hope this will help Without changing sumPromise
React.Js and Typescript how to read data from JSON?
everyone. I am using MongoDB with mongoose and React.Js. I have a page where the user can display a post. I am sending fetch request to the backend where I am getting this json data as response. And on the frontend I am using Fetch API, to get this data, what I am trying to do is I want to
How can I remove a number of objects in an array?
I have an array like this : I only want two of each of category object in the array and remove the rest If the number of objects of that category is over 2 and get something like this : How can I remove the rest of the objects of a specific category If the number of those objects in
How can I map over an object and set it to another object without overwriting the previous values?
I’m working with a form that has sections where there can be multiple addresses, ids, etc. I’m taking the value of those objects and mapping it to another object that my API can understand. The problem I’m having is that when I have more than two addresses or ids my function overwrites all t…
Find how many times a char is included into an array of names
I’m trying to do the following exercise in JavaScript: I need to return the number of times the letter ‘l’ is used inside an array of names. This is an example of the array I have to use: Note that the letter ‘l’ might be repeted inside a single name. Is there any JS method I cou…
Filter array object by type and compare key
I have two arrays, in one (aux) I get key and value. In the second array of objects (result) I have the attribute “correlati” and what I’m looking for is that if the key of the array “aux” is equal to the attribute “correlati” then it pushes that result in a new array…
Looping over an object to change values inside
I am trying to send an object to an api and my object contains arrays that I want to turn into strings. However I am having trouble returning the new object with the arrays turned to strings. My goal is to have a copy of the original object with all the arrays turned into strings. Answer You are not assigning