Skip to content
Advertisement

Tag: arrays

Array item gets the value “undefined”

I am trying to create an array of unique numbers from 0 to 10: But the output of the array will always have an undefined item at a random index which I don’t know why. Can somebody help me out? Answer If the new Set removes a duplicate, then i will be larger than the length of numbers, due to

Modify values inside a Javascript object

I have the following array if objects: Then i elaborate the following one: is it possible to change the value of ‘options’ array of the first one, according to the second set of options? i need to obtain something like: Answer i solved this way (locattributes is the first object, newopt the second) i don’t know if there is a

How to sort multi-array / nested map by value (e.g. from Firestore) in JavaScript

I’m trying to get a multi-array / nested map sorted by value via JavaScript / TypeScript. My array currently looks like this: Now I’d like to sort by the [‘information’][‘name’] values like this: Does anybody know how to do that? I’m especially struggling with the nested stuff… Thank you in advance! Answer Using String.prototype.localeCompare, you can compare the string values

Use recursion on array [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 2 years ago. Improve this question Write a function that by given array of integers, and a positive number X, returns the product of all odd

Function to create multidimensional object

Hello I’m strugglling with write everything from multi depth ul list into one object. I’ve got something like this. Depth One 1Depth Two 1Depth Three 1Depth Three 1Depth Two 1 Depth One 2Depth Two 2Depth Three 2Depth Two 2Depth Three 2Depth Three 2Depth Three 2 Depth One 3Depth Two 3Depth Three 3Depth Three 3Depth Three 3Depth Three 3Depth Three 3Depth

Calculating difference between 2 items in JavaScript object

I have some customer data in an array of javascript objects that looks as such: I would like to loop over and get the difference between food_cost and prev_year_food_cost for each client. So ideally, I would have a new object containing client, food_cost and the difference. I have tried this but its not quite right. It’s pseudo code. Answer You

Advertisement