Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 1 year ago. Improve this question I’ve been trying to sort string inside an object which is inside an array. By splitting…
Tag: arrays
Is there a way to combine all elements in an array?
So I’m making a website, and I want to string together all the items in an array. e.g: Does anyone know how to do this? Answer join will join all elements in the array with the specified delimiter (use empty string ” since the default separator is comma ,)
Javascript sort array of objects alphabetically AND put first objects with value
I’m trying to sort this data which contains various arrays of objects, the console.log of myData is something like: I’m trying to sort it alphabetically (based on value of name) and if the object has the parameter url , put it at the beginning. So the output would be: what I tried is this, and man…
How to push object keys to an array multiple times based on their integer values in JavaScript
I’ve looked on several sites including through the suggested answers when posting this question, so forgive me if it’s been answered elsewhere. I’m very new to JavaScript (and coding in general). I’m working on a ‘weighted lottery’ project and I have an approach in mind tha…
Array inside an map function seems to receive data, outside the map it was empty
I’m making a simple GET and POST with NodeJS and Express just for learning a little about PrismaJS with MySQL database. I want to pass the value of the array grouped to the creating function, when I use console.log(grouped) inside the map function I have the values I want, outside it keeps empty [], als…
Regex to split a string into args without breaking the quoted text
I want to take all words from a string and convert them into an array, but i don’t want to break sentences that are enclosed in quotes My code: What do I need as a result: Answer One simple approach would be to use string match() along with the regex pattern “.*?”|w+. This pattern will eager…
How to do a join from 2 JSON by a common ID field in Javascript
I have two JSON files: JSON A has some company properties and the company_id, while JSON B has company names and company ids. JSON A example: JSONB example: Which is the most efficient way to do a join by the company_id values? I would like to have the JSON C (merged result) with the company names correctly a…
Comparing two arrays of objects for matching properties then creating two new arrays
I have the following two arrays: I need to end up with a newArray containing only one object per Id, but if the ids in an object in the oldOrder array and newOrder array then I need to get the difference in the Qty positive or negative. So for example the above would create this new array: I would also
Merge multiple objects in array by id – javascript
This is my first question, so please be gentle 🙂 I know my question is similar to many others, and I have tried a LOT of solutions, but I’m not getting the result I need. I have an array of objects that can have duplicate id’s. There are 3 objects for id ‘THOM01’: The objects with the …
Find and change item in Javascript array of arrays
I am trying to find and change a item that is inside of an array of arrays. My array is like that: The way i’m doing it now is using a forEach: The problem is that I can’t stop the loop and I believe there must be a better way, maybe using the ‘find’ command. I can do this with