Update single column in 2-D array

I have a 2-dimensional array like below. The first column is a date and I would like to store it as a number of milliseconds using the getTime() function so that I can use it for date comparisons later. Is there an easy way to update a single column in a 2-d array? The original array could have multiple columns. I’m trying to update the date column here which is the first column. So for example, instead of Mon Aug 10 00:00:00 GMT-05:00 2020, it should have value returned by getTime() on the date object represented by Mon Aug 10 00:00:00 GMT-05:00 2020

 [[Mon Aug 10 00:00:00 GMT-05:00 2020, 7.7107286E7, A-Plus Restoration], 
[Sun Feb 09 00:00:00 GMT-06:00 2020, 7.1324511E7, Kwik-E-Mart Industries], 
[Sun Mar 08 00:00:00 GMT-06:00 2020, 7.5233927E7, Jacob Tannenbaum], 
[Wed Mar 25 23:00:00 GMT-06:00 2020, 7.7678662E7, Music Depot]]


You could try something like this:

someData.map((data) => 
     data[0].getTime(), // Does the transformation for column 1
     ...data.slice(1)   // Picks all columns except one and spreads them out

Leave a Reply

Your email address will not be published. Required fields are marked *