What is the process for transforming a multi-dimensional array containing strings into a multi-dimensional array containing numbers?

I've got a unique structure of data composed of arrays with strings as seen below:

 [    
 0: Array(1)
    0: Array(6)
        0:  [5.379856, 43.252967]
        1:  [5.422988, 43.249466]
        2:  [5.425048, 43.245153]
        3:  [5.383804, 43.239838]
        4:  [5.399856, 43.212967]
        5:  [5.379856, 43.252967]
1: Array(1)
    0: Array(6)
        0:  [5.39014, 43.279295]
        1:  [5.393069, 43.279249]
        2:  [5.391814, 43.278421]
        3:  [5.390709, 43.278749]
        4:  [5.3909, 43.2785]
        5:  [5.39014, 43.279295]
 ]

The values are currently in string format and I'm looking to convert each one into a number. Could anyone provide guidance on how this can be achieved without utilizing loops?

Appreciatively,

Answer №1

If the array contains numbers instead of strings, you can still convert them to numbers by utilizing the map() function along with Number().

var data = [
  [
    ["5.379856", "43.252967"],
    ["5.422988", "43.249466"],
    ["5.425048", "43.245153"],
    ["5.383804", "43.239838"],
    ["5.399856", "43.212967"],
    ["5.379856", "43.252967"]
  ],
  [
    ["5.39014", "43.279295"],
    ["5.393069", "43.279249"],
    ["5.391814", "43.278421"],
    ["5.390709", "43.278749"],
    ["5.3909", "43.2785"],
    ["5.39014", "43.279295"]
  ]
];

data = data.map(arr => arr.map(item => item.map(value => Number(value))));

console.log(data);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Angular material 10 is having trouble fetching the icon named "mysvg". It seems that a user login is needed

Unfortunately, I am unable to replicate this issue in my project as I utilize authn/authz. The problem seems to be related to a custom SVG. Below is the IconService code snippet: @Injectable({ providedIn: "root", }) export class IconService { construc ...

Angular 5 error handler does not support service calls

My HTTP calls are placed inside a service, as they should be. Within that service, I inject another service for handling error notifications. In an interesting turn of events, I noticed that when I place the notification call inside the catchError pipe, e ...

When you call setTimeout from a static function, it does not get executed

Having a problem with starting a timer in my utility typescript class. The static function initTimer() uses setTimeout but when called from a react component, the timer doesn't start. StyleWrapper.tsx const StyleWrapper: FC = (props) => { cons ...

Route Handler 13 is encountering difficulties in retrieving data from the body in the (app/api/auth) endpoint

Whenever I attempt to retrieve the body from the new export async function POST( req: Request), it seems to come through as a stream instead of the expected content type. The route handler can be found in api/auth/signup See folder layout image export asyn ...

Angular 8's cutting-edge feature: the dynamic password validator

Hello, I have an API that returns an array object called passwordPolicy with the following properties: PasswordMinLength: 6 passwordMinLowerCase: 1 passwordMinNumber: 1 passwordMinSymbol: 0 passwordMinUpperCase: 1 The values of these properties can change ...

Creating a dropdown menu in Ionic 2 with dynamically populated options and a pre-selected value using ng

After scouring the depths of the internet, I have yet to find a suitable solution to my current dilemma. The code I have generates a list of options dynamically from an API and is functioning perfectly. <ion-select formControlName="d ...

What is the correct method for storing a response in an array variable in Angular?

I am looking to save the response data from an API call in a variable and display it in the component.html file. Component.ts file : public coinsHistory = []; this.service.getCoinsHistory().subscribe( (response) => { this.handleCoinsRespon ...

When exporting data to Excel, the date is automatically adjusting based on the timezone. Is there a way to prevent this from happening

Whenever I attempt to export data to excel in angular, I encounter an issue with time zones. The date in the database is set in timezone 'x', while I am exporting data from timezone 'y'. As a result, the exported data in Excel displays ...

When invoking the function, the original state remains unaffected within a separate function

Whenever I click on an 'item', it should establish an initial value for me to use in a comparison within another function that involves the mousemove event. However, when the mousemove function is triggered, the initial state remains at 0. imp ...

What is the best way to construct an interface in TypeScript with a variable number of properties?

Is it possible to create an interface in typescript with a variable number of string properties, ranging from 5 to potentially 50? ...

Issue with Next.js: Router.push not causing page to refresh

I'm currently developing a next.js page called /page/data/[dataId] (this page is accessed when a user clicks on a link from the page /page/data, where I fetch the list of items through an API). When a user clicks on a button, I make an API call to de ...

Developing an Angular filter using pipes and mapping techniques

I am relatively new to working with Angular and I have encountered a challenge in creating a filter for a specific value. Within my component, I have the following: myData$: Observable<MyInterface> The interface structure is outlined below: export ...

Oops! An error occurred: Uncaught promise rejection - invalid link found for ProductListComponent

I am currently in the process of learning Angular and Ionic, but I am feeling a bit confused as to where my mistake is. I have looked at other questions, but I still can't seem to figure it out. Can anyone provide some assistance? Perhaps someone has ...

Guide on utilizing a provider's variable in another provider within Ionic 2/3

In my code, I have a boolean variable called isConnection that is used to monitor network connection status. This variable is defined in a provider named 'network' and can be set to either true or false in different functions. Now, I need to acc ...

Is there a way to clear the selected date in a date picker while using MatDateRangeSelectionStrategy?

Recently, I was experimenting with the date picker feature of Angular Material and stumbled upon this particular example After implementing this example with my own logic, everything seemed to be working perfectly fine except for one issue. The dates were ...

Is there a way to automatically extend my content to fill the space on the page below the Material UI AppBar?

I am currently using React and Material UI React to develop my application. My goal is to implement the AppBar component with content underneath, without causing the entire page to scroll. I want the content to occupy the maximum remaining height and the f ...

What's the Best Way to Add a Custom Flag to the `nx angular serve` Command Without Triggering an Error?

When running the nx angular serve command, I want to add my custom flag (-t example). But when I try this, I get an error message from nx that says: 't' is not found in schema To address this issue, I plan to capture this flag in proxy.mjs an ...

Nest JS is currently experiencing difficulties with extending multiple classes to include columns from other entities

Currently, I am immersed in a new project that requires me to enhance my entity class by integrating common columns from another class called BASEMODEL. import { Index, PrimaryGeneratedColumn } from "typeorm"; export class BaseModel { @Prima ...

Is there a way to execute Angular code synchronously similar to how it is done in C#?

Trying to replicate a C# application in Angular is proving to be challenging for me, particularly when it comes to ensuring that the code runs synchronously. Consider the following example: private void doChecks() { if (isInvoiced()) return; ...

Issue encountered: Nuxt 3 fails to locate the useRoute import

Recently, I updated to the latest version of Nuxt and encountered an issue with the useRoute method. Even though it works, I keep getting a "Cannot Find name useRoute" error message. Can anyone help me figure out what might be missing? <script lang=&quo ...