Your code does work, although it's the order in which you call it in - is what may be stumbling over a little. As demostrated in this Fiddle.
functions.php
<?php
/**
* Load:
* css; chosen; jquery.
**/
function wordpress_scripts() {
wp_enqueue_style(
'chosen.css',
get_stylesheet_uri()
);
wp_enqueue_script(
'chosen.js',
get_template_directory_uri() . '/js/chosen.js',
array('jquery')
);
wp_enqueue_script(
'myscript.js',
get_template_directory_uri() . '/js/myscript.js',
array('jquery')
);
}
add_action( 'wp_enqueue_scripts', 'wordpress_scripts' );
?>
myscript.js
<script>
jQuery(document).ready(function(){
var arr = ["1", "2"];
jQuery("#location option").each(function () {
if (jQuery.inArray(jQuery(this).val(), arr) != -1) {
jQuery(this).prop('selected', true);
};
});
if ( typeof jQuery.fn.chosen !== 'undefined' )
jQuery("#location").chosen();
});
</script>