I am Trying to convert the array [ '9:00', '9:40', '9:50', '11:00', '15:00', '18:00' ] to [ '900', '940', '950', '1100', '1500', '1800' ] in javascript.
You can do it in this way:-
let oldArray = ['9:00', '9:40', '9:50', '11:00', '15:00', '18:00'];
let newArray = oldArray.map(elem => elem.replace(':',''));
console.log(newArray);
What you're looking for is the .map() function. This function iterates over all items in the array, allowing you to execute code on said iterations. Use what I've provided below.
const arrayOfTimestamps = [ '9:00', '9:40', '9:50', '11:00', '15:00', '18:00' ];
const formattedTimestamps = arrayOfTimestamps.map(time => time.replace(/:/g, ''))
As an explanation, .map() iterates over each item, and the time is being handled by regex. the /g aka global flag tells the regex to remove all semicolors's from the strings.
For more information on how .map() works, here.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
Although there are other solutions that use less lines of code, the following is easier to read. Loop through your list of dates and for each date, replace the colon character with a blank.
var list = [ '9:00', '9:40', '9:50', '11:00', '15:00', '18:00' ];
for (var i = 0; i < list.length; i++)
{
list[i] = list[i].replace(':', '');
}