• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: How to use .map() ? I want to select querySelectorAll() + .map() to return Array with Index(name)

Resolved: How to use .map() ? I want to select querySelectorAll() + .map() to return Array with Index(name)

0
By Isaac Tonny on 16/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I need to create a variable array with index (name) = value, referring to html, example of what this array would look like:
In my Html I’m using the .map() function to get the values but the array that is formed has an automatic index, how to define the array’s index so that it is equal to the name field??


Answer:

You are trying to create an object with properties, not an array. If you are coming from another language, then it may be confusing that JavaScript uses array-like syntax to access properties (called bracket notation).
You can use reduce because you are reducing multiple elements of an array to a single object:


If you have better answer, please add a comment about this, thank you!

arrays javascript
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: TypeScript does not recognize properties when instantiating interface array

27/03/2023

Resolved: How to make statement case insensitive when uploading a dta file with specified columns?

27/03/2023

Resolved: Sort dataframe columns value by close it to another column

27/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.