JavaScript: changing text to numbers within an array

Looking at this array of strings:

["5:17", "8:22", "3:34", "5:23", "7:12", "7:24", "6:46", "4:45", "4:40", "7:58", "11:51", "9:13", "5:50", "5:52", "5:49", "8:57", "11:29", "3:07", "5:59", "3:31"]

I'm curious, how do you suggest converting these string values into numbers?

Answer №1

To implement the "map" function, you can follow this example:

arr.map(data => {
    let [hours, minutes] = data.split(':')
    return +hours * 60  + +minutes
})

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

Getting the value of a JSON object in CodeIgniter can be easily achieved by using the appropriate

My current project involves using the codeigniter framework to build a website. I am making an AJAX request with jQuery to retrieve data from the server. I have experimented with two different methods of receiving the data: one in a PHP associative array a ...

Geocomplete Plugin without Google Branding

I've implemented the jQuery Geocomplete Library. This is what I have accomplished so far- $(function() { $("#find_product_location").geocomplete( { map: "#product_location", mapOptions: { mapTypeId : 'roadmap',//roadmap, satellite,hybrid ...

Add information if the data does not exist, modify it if it does

My current project involves creating a TS3 bot using the Node.js Library from Multivit4min on GitHub. The purpose of this bot is to perform the following tasks: nick (txt) cldbid (int) clid (txt) lastChannel (int) Event #1 - When a client connects to a ...

How can I incorporate a second main app.js file in Node.js to improve the organization and cleanliness of my codebase?

Hello, I am currently using Node.js and the Express framework for my project. All of my server-side code is contained within my app.js file, which has become quite complex with almost 250 lines of code. Now, I need to add authentication functionality to my ...

The preselected value in an AngularJS select box is set to static HTML by

In my HTML, I have a select tag that I am populating using ng-repeat. <td> <select ng-model="item.data.region" style="margin-bottom: 2px;"> <option ng-repeat="region in vm.regions track by $index" value="{{region}}">{{region} ...

JSON.stringify function provides detailed information about the indexes and length of an array

When using AJAX to send an array to my controller, I find it convenient to convert it to JSON format. This is how I construct my array: $("#selectedDropdown option").each(function () { selectedLanguages.push($(this).val()); }); To stringify it, I ...

What's the reason behind the data not being retrieved by $.ajax?

After attempting to validate a form and send the values using $.ajax, I encountered an error message stating "Undefined index: is_ajax". Why is the form_data not being received? What could be causing this issue and how can it be resolved? function validat ...

Is it possible to locate and substitute content with a variable in Visual Studio Code?

In my dataset, there are some numbers that are too large to be int values (>2147483647). When they exceed this limit, they are recorded as "price_amount" : { "$numberLong" : "3900000000" }. However, I have updated the data ...

The PHP time search function is experiencing technical difficulties and is not functioning correctly

I'm experiencing issues with adding a time search feature to my PHP site. The date search is functioning correctly, but when attempting to incorporate the time search, it doesn't seem to be working as expected. For instance, selecting 13:00 as t ...

In the year 2021, eliminate linked documents using mongoose/MongoDB middleware

After extensive research on stack overflow, I attempted various solutions for deleting referenced documents in MongoDB using node.js. Unfortunately, most of them either utilize deprecated methods or simply do not function as expected. Within my applicatio ...

Why bother serializing arrays before saving them in the database?

It's interesting to observe how individuals save arrays like this: a:6:{i:0;s:5:"11148";i:1;s:5:"11149";i:2;s:5:"11150";i:3;s:5:"11153";i:4;s:5:"11152";i:5;s:5:"11160";} Why can't they simply be: 11148,11149,11150,11153... and have the databa ...

Using plain JavaScript (without any additional libraries like jQuery), you can eliminate a class from an element

I'm attempting to locate an element by its class name, and then remove the class from it. My goal is to achieve this using pure JavaScript, without relying on jQuery. Here is my current approach: <script> var changeController = function() { ...

Enable divs to be interactively chosen

I have created two selectable divs that function like buttons. By using the left and right arrow keys, I am able to select one of the divs with this code: document.addEventListener("keydown", keyDownDocument, false); function keyDownDocument(e) { var k ...

Creating a dynamic user interface with multiple tab navigations using jQuery on a single web

On my current HTML page, I am facing an issue with multiple tab navigations. When I click on one navigation, it also affects the other tab navigations. I cannot seem to find a way to only affect the tab navigation that I am clicking on without hiding the ...

Troubleshooting color inconsistency in ApexCharts tooltips using JavaScript

My attempt to change the tooltip color to black seems futile as it continues to display in white. Consequently, when a user hovers over the graph, it remains in its unaltered state with poor user design. To gain better insight, refer to the image below: h ...

What is preventing python from eliminating these numbers from my array?

My goal is to eliminate all numbers within the range of 0 to 1000 that have fewer than two digits. This is my approach: numbers = range(0,1001) #validate for two or more digits for number in numbers: if len(str(number)) < 2: numbers.remove( ...

The function you are trying to call in Node.js is not defined

Just starting out with NodeJs and trying to implement async/ series, but encountering an error: task.save is not a function Here is the code snippet I am working with: async.series([ (cb) => { Task .findById(id) ...

Organize results from MySql using php

Trying to retrieve table values from a MySQL database sorted has proven to be a challenge for me. While I am able to connect and update the table successfully, I struggle with displaying the messages in the HTML chat history sorted by time. Is there a mo ...

Is it possible to read JSON data from a POST request using Django DRF?

When attempting to send data via a jQuery POST request, I am able to access the data from both the JavaScript client side and the Python Django Rest Framework serializer create method on the backend. The console.log output is: { "wo_r": [ { " ...

The route to the template file within a JS script in a Symfony/Angular project

I am currently working on a project that utilizes both AngularJS and Symfony, but I'm struggling to correctly define the path of a twig template in my JavaScript code. I need to locate: -the original JS file -the template file ...