How to seperate the number from the string

How to seperate the number from the string
0

#1

i’m trying to get the duration just like this;

“duration”:“2h 22min”,
to
“duration”:“142”,

`{
title: ‘The Godfather’,
year: ‘1972’,
director: ‘Francis Ford Coppola’,
duration: ‘2h 55min’,
genre: [‘Crime’, ‘Drama’],
rate: ‘9.2’
}

function turnHoursToMinutes() {
var newArray = movies[1].duration.split(’ ')
return newArray[0];
}
turnHoursToMinutes();`


#2

There are a couple of ways of doing this. One way, would be to split the the string using "h " as the delimiter. This would make the first element of the array returned the “2”. Then you would need to split the second element of the returned array using “min” as the delimiter. This would allow you to reference the first element of the array returned to capture the “22”.

Finally, you would need to convert the strings to numbers and multiply the hours by 60 and add to the minutes part.