0

Am receiving data in form of {room1: 4, room2: 2}

received in a name of roomData

$scope.testdata = [{
        'room': 'room0',
        'users': '10'
    }];

$scope.setLobbyRoom = function (roomData) {

    $scope.inc = 0;
    for (i in roomData) {
        //want to push the data into the array list here.
    }
}
3
  • which object you want to push data in and what form of object you want finally? Commented Jul 14, 2015 at 5:18
  • I need push the roomdata "{room1: 4, room2: 2} " to testdata. which is used for repeat. Commented Jul 14, 2015 at 5:27
  • If rooomData is an array of data like this {romo1: 4, room2:2}, How come You first data in testData i ssomething like {'room' : 'room0', 'users' : '10'}, while its should be something like testData = [ {room1:4, room2:2}] Commented Jul 14, 2015 at 5:40

3 Answers 3

1

If you want to push the data to $scope.testdata, all you have to do is to use the method push

$scope.testdata = [{
        'room': 'room0',
        'users': '10'
    }];

$scope.setLobbyRoom = function (roomData) {

    $scope.inc = 0;
    for (i in roomData) {
        $scope.testdata.push(roomData[i]);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

1

Is roomData an array? If so, it's as simple as:

$scope.testData = $scope.testData.concat(roomData);

Comments

0
$scope.testdata = [];

$scope.setLobbyRoom = function (roomData) {
    $scope.testdata = [];
    for (i in roomData) {
        $scope.testdata.push({
            room: i,
            users: roomData[i] 
        });
    }
}

This works

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.