C
C
Captha2016-02-23 15:46:47
Arrays
Captha, 2016-02-23 15:46:47

How to take an array out of a function in JS?

Good day to all, please tell me how to take out an array with cities for a function so that you can access it globally? I'm a newbie myself :)
function initInputHint() {
$.get('?cities=cities', {}, function (cities) {
var arr = new Array();
var i = 0;
$.each(cities, function (index, obj) {
if ('ru' in obj.name_translations) {
arr[i++] = obj.name_translations.ru;
}
});
$('#form-avia input.hint').autocomplete({source : arr});
});
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Prk11, 2016-02-26
@Prk11

just declare it before the function.
var cities = new Array();
function initInputHint() { .... }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question