In PHP we can use:
$validation = [
200 => ['icon-check', 'The key match with the message!'],
400 => ['icon-close', 'The key doesn\'t match with the message!'],
403 => ['icon-close', 'Impossible to verify, the key or text can be wrong!']
];
This way we can get the result using $validation[200][0]
to return icon-check
.
However, I can not do the same in Javascript:
var validation = [
200 => ['icon-check', 'The key match with the message!'],
400 : ['icon-close', 'The key doesn\'t match with the message!'],
403 = ['icon-close', 'Impossible to verify, the key or text can be wrong!']
];
All types of attempts fail, both with
=>
,:
and=
.
My only choice was to set the index on the variable:
var validation = [];
validation['200'] = ['icon-check', 'The key match with the message!'];
validation['400'] = ['icon-close', 'The key doesn\'t match with the message!'];
validation['403'] = ['icon-close', 'Impossible to verify, the key or text can be wrong!'];
However, is there an alternative without having to repeat validation[XXX] = [...]
?