Well, I’m completely new to JavaScript.
Can you please tell me what type of data is this JavaScript code:
var options =
{
sourceLanguage: 'en',
destinationLanguage: ['hi', 'bn', 'fa', 'gu', 'kn', 'ml', 'mr', 'ne', 'pa', 'ta','te','ur'],
shortcutKey: 'ctrl+g',
transliterationEnabled: true
};
I’ve reviewed JavaScript arrays, but it doesn’t seem to be a traditional array.
Still don’t know if it’s some kind of arrays or another data type!!
Additionally, is there any way to set individual elements to that data type such as setting array elements individually.
Thanks in advance
This is a way of creating and initialising an object in javascript called an object literal. Since javascript is dynamically typed, you can add key/values at any time, even to the built in objects.
The equivalent code for this would be:
The square brackets [] denote an array. The equivalent for this would be
You access array elements by index eg destinationLanguage[0].
As you can see it is much more readable and convenient to to initialise everything using the notation in your request.
This notation forms the basis of something called JSON (Javascript Object Notation) which is wire format for passing information eg between client and server. The string in your example could be retrieved via an AJAX request and parsed in a number of ways into a complex object.