Trafalgar D Law Trafalgar D Law - 18 days ago 4x
Javascript Question

Is there any short way in my current method of code?

I have this snippet code below. For me I think this is a long method. Is there any short method for this? Thanks

var aaa = '1:00 AM'
var bbb = aaa.split(" ");
var ccc = bbb[0],
ddd = bbb[1];

<script src=""></script>
<input type ="textbox" id = "time">


First of all, better variable names would greatly help future developers. aaa carries almost no meaning.

Secondly, just make your expressions more direct. Save variables for when you need to break your code into smaller chunks:

var time = '1:00 AM'.split(" ");
var hour = time[0],
    twelve_hour_suffix = time[1];

There are a lot of ways to make it shorter (even single-liners), but I feel this is sufficiently small and direct that readers will understand it easily.