Code to fetch object array data from server:
var tag_Arr= [];
var fbref = firebase.database().ref();
fbref.child('tags').limitToFirst(1).on("child_added", function(e) {
// console.log(e.key + ' ' + e.val().tagname);
var obj = {id:e.key, text:e.val().tagname};
tag_Arr.push(obj);
});
array object hard coded in Js
var data2 = [];
var obj1 = {id:0, text:"ding"};
data2.push(obj1);
Why is the console log output is different for these two,
console output screenshot with expanded
How do I convert the first array just like the second one? because first output is not loading in Select2 Jquery textbox and 2nd one is loading.
I am loading the firebase results in to an array object and then pushing that data with select2. select2 code with firebase input is below,
var dataNew = tag_Arr;
$(".myselect").select2({
placeholder: "select a tag",
data: dataNew
});
"dataNew" is not loading. but if I give " data2" it is loading.
Even, I have tried to parse the Firebase output through JSON.parse but its throwing uncaught exception error.