All I want to get an array object like this: Instead I’m getting: Answer There is some way to get the structure you want: ref: Array.prototype.flat() Array.prototype.reduce()
Tag: arrays
pivoting array of object data javascript
so i have an array of object like this: it try to get the summary or pivot value of the dates, but i get this result instead of what i expected: my expected result should be like this: i try to get the summary total of the dates base on the date array… or is it possible to get this
Can you use JSON.stringify on an array with objects? [closed]
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers. Closed 3 months ago. Improve this question
When traversing nested object and using match to give filtered object results in javascript it returns array of [object], [object] etc
Context I am using: Windows 11, VSCode and node v18.12.1 The code I am working on is trying to traverse several JSON objects. Then, using an array variable, the code needs to filter on certain attributes in each object, as there is more than one value that needs to filter against in each name attribute in each object. Question The
How do I find an exact substring match in an array in JavaScript?
I’m having trouble trying to find a substring within a string. This isn’t a simple substring match using indexOf or match() or test() or includes(). I’ve tried using these but to no avail. I have a bunch of strings inside an array, and then either need to use filter() method or the some() method to find a substring match. I
How can I pass a variable to be used as the condition in a filter?
I am trying to filter an array of full names by a specific first name. I have created the filterFirstName function which accepts arguments for the name and the criteria to compare it to. I then use that function in my filter. I looked up the syntax for filter callback(element[, index[, array]]. The element is the fullName but the nameQuery
Need of a call(), apply() and bind() method
I have read lot of theory regarding call(), apply() and bind(). I am not able to understand if we can call method directly why we need call() , apply() or bind()? Can somebody explain in laymen terms and little in terms of JavaScript? Answer That’s the flexibility offered by Javascript, an object and it’s method don’t have to be coupled
Copy obj filtering selected elements in javascript
I’m trying to create a new obj similar to my input, but containing only the elements from a selected id list. Answer Use Array.filter
I can’t write the second data in my object to div
I can’t write the second data in my object to div Note : i put here the css codes cause maybe should necessary OUTPUT despite can write “comments.yorum” , why ı cant write “comments.isim” i’ve tried to write comments.isim to div , i can’t write comments.isim despite can write comments.yorum,I couldn’t see comments.isim Answer The issue was caused by your
Convert 2D JS array to json string
My array in variable is: I’ve mentioned key and value here for the 2D array, I’m trying to convert this to JSON string. I tried JSON.stringify(arraydata), arraydata is the variable where the array is stored, but it makes the string empty, whereas array data is correct. Edit: This is how I’m adding array data: Answer The “array” quoted in your