How to change script order?

wp_enqueue_script has $deps parameter which exactly does what you need.

wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer )

Let’s say that your custom code is in a file named custom.js which is enqueued with a handle my-custom and you want this to be loded before my-script1 which is en-queued with a handle.

wp_enqueue_script( 'my-custom', '/path/to/customjs', array() );

wp_enqueue_script( 'my-script1', '/path/to/script1js', array('my-custom') );

The above code says that my-custom is a dependency for my-script1.