esc_js()
is intended for escaping data for use within an HTML attribute.
If you want to escape data for use within an inline script, wp_json_encode()
should be sufficient.
For example:
var disabledDays = <?php echo wp_json_encode( $iva_disable_days ); ?>;
This outputs:
var disabledDays = ["4\/7\/2018","11\/18\/2017"];
If you check the variable in your dev tools console, you will see that it is being parsed correctly:
However – if you absolutely do not want escaped slashes (not recommended), the second param to wp_json_encode()
is a bitmask of options:
var disabledDays = <?php echo wp_json_encode( $iva_disable_days, JSON_UNESCAPED_SLASHES ); ?>;
This outputs:
var disabledDays = ["4/7/2018","11/18/2017"];
For a list of available options, check the PHP json_encode()
docs.