3
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 obtain the result using $validation[200][0]
to return icon-check
.
However, I can’t 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 kinds of attempts fail, both with
=>
, with:
and with=
.
My only alternative was to set the index in 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 any alternative without having to repeat the validation[XXX] = [...]
?
I believe I can do something similar with object:
var validation = {200: [...]}
, but I don’t know if it’s the best approach.– Woss
http://answall.com/questions/41140
– Daniel Omine
http://answall.com/questions/173916
– Daniel Omine