No PHP podemos utilizar:
$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!']
];
Dessa forma podemos obter o resultado utilizando $validation[200][0]
para retornar icon-check
.
No entanto, não consigo fazer o mesmo no 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!']
];
Todos tipos de tentativas falham, tanto com
=>
, com:
e com=
.
Minha única alternativa foi definir o índice na variável:
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!'];
Entretanto, existe alguma alternativa sem ter que repetir o validation[XXX] = [...]
?
var validation = {200: [...]}
, mas não sei se é a melhor abordagem.