I tried a lot of algorithm to convert my Array with objects inside into an array of arrays. But each time either it doesn't work or my new create array is empty. For exemple, I can't run into it with angular.foreach()
or myArray.forEach(function(element))
. I really don't know why, because it is declared and initialized as an array "var myArray = [];"
.
Then I'm using push
to populate it, and what I obtained in the console.log is :
What I would like to have is something usable into _.SortBy(myArray, 'date');
(Underscore.js) to do it I need myArray
to be like that :
var stooges = [{name: 'moe', age: 40}, {name: 'larry', age: 50}, {name: 'curly', age: 60}];
Following this post : Converting a JS object to an array I tried barely everything listed, but nothing worked...Can you give me a hand ?
$scope.myArray = [];
// This is into an angular.foreach
$scope.myArray.push({'Name' : snapshot.val().name, 'Link' : snapshot.val().link, 'second' : snapshot.val().second, 'var' : snapshot.val().var, 'selfID' : 'MyID', 'date' : snapshot.val().date, 'hour' : snapshot.val().hour });
console.log("MyArray :", $scope.myArray);
EDIT :
It seems there is a problem with my array, i tried this two function, but i couldn't see any console.log()
... Is it possible that my array is locked ? Maybe no function (sort, _.sortBy...) can run into it ?
// One try to run into and sort
$scope.myArray.sort(function(x, y)
{
var date1 = new Date(x.date);
var date2 = new Date(y.date);
console.log("My dates :", date1);
console.log("My dates :", date2);
return date1 - date2 ;
});
// An other try to run into my array
for(var i = 0; i < $scope.myArray.length; i++)
{
console.log("I'm in "+i+" with : "+$scope.newCal[i]);
}
// Even is showing the complete Array in console.log is working, this below shows me "undefined"
console.log("One element : "+$scope.newCal[1]);