[Solved] Convert JSON to array in Javascript


You could splice the values and get only the first two elements as number.

var array = [{ time: "18:00:00" }, { time: "10:00:00" }, { time:"16:30:00" }],
    result = array.map(o => o.time.split(':').slice(0, 2).map(Number));
    
console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }

If you have JSON sting, then you need to parse it with JSON.parse first.

var json = '[{"time":"18:00:00"},{"time":"10:00:00"},{"time":"16:30:00"}]',
    array = JSON.parse(json),
    result = array.map(o => o.time.split(':').slice(0, 2).map(Number));
    
console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }

3

solved Convert JSON to array in Javascript