I have a question about declaring a variable in an object. Assuming that global or window is also an object, why is it not possible to declare a variable using let in an object that is a child of the window object? I do not understand that. Thanks for the answer and sorry for the English but I hope you
Tag: object
How to append a property to another property of type object in JavaScript
I am trying to figure out how to append a new value to the same property of an object. I have this code below: The value [member.displayName] changes every for loop, and I want every loop to create a new value within [todaysDate] with [member.displayName] property name. It currently replaces property names with the next name from the row, instead
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 element is added to the array. Why
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 the additional ones with the last one
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 that looks like the following : code:
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
js: fill object with array elements using reduce()
trying to learn reduce() but can’t understand it well yet. Maybe someone from you could help me with my problem. I have an object with defined keys and an array. I would like to fill up the objects keys with the arrays values using reduce(). My sandbox LINK Till now I tried something like this: expected result: Thanks for any
Sort array of objects based on another array of objects key
I have 2 arrays of objects I need to sort array2 to match the same order of array1 based on the property name. In array2 there are 2 names properties equal with value B. These name B are together but i need the array to be in the exact order of array1. In array1 the first B is at index
Is pushing an object to an array async operation?
I was doing one problem-solving program where I had to find all the pairs from an array that adds up to a target (classic two-sum program just with a little addition). This was my first approach: ** This should output: [{first: 8, second: 2},{first: 7, second: 3}] but instead it prints: [{first: 7, second: 3},{first: 7, second: 3}] ** Now
how to store the value of a key for a object and pass it to the function which is a value of another key in the same object
In the above object inside dateFilter for value i am using a calculateAverage function to get the value i need to pass the same value as parameter for calculatePercentage which is a value for percentage key in the same object how to store the calculateAverage at dateFilter and pass it to calculatePercentage so that i can avoid calculating average two