2

I'm trying to use .concat() to concatenate two objects, but it returns

tiles.concat is not a function

This is the code (angular app and coffeescript):

  $scope.tiles = new UI();
  $scope.tiles.loadUITiles();
  console.log($scope.tiles);

  $scope.rooms = new RoomData;
  $scope.rooms.load();

  buildSavedRoomsScope = (tiles,rooms) ->
    console.log "tiles: " + tiles + " ||| Rooms:" + rooms
    savedRooms = tiles.concat(rooms)
    i = 0
    while  i < savedRooms.length
      room = savedRooms[i]
      room.saved = !room.hasOwnProperty('saved')
      room.uid = (if room.saved then 'saved-' else 'notSaved-') + room.id
      i++
    room


  $scope.savedRooms = buildSavedRoomsScope($scope.tiles, $scope.rooms)
  console.log $scope.savedRooms

I don't understand what I'm doing wrong, as it look to me just like this

EDIT

Just like in the example, my JSON data is an array of object (same structure as the example above)

6
  • What is tiles at that particular moment...? Commented Mar 2, 2016 at 11:35
  • tiles: [object Object] ||| Rooms:[object Object] Commented Mar 2, 2016 at 11:35
  • That don't help much. Do a console.log tiles to see exactly what it is. Commented Mar 2, 2016 at 11:36
  • console.log returns what i just copied in the comment above, there is already a console.log in the code, the first line in buildSavedRoomsScope function, and it returns the above Commented Mar 2, 2016 at 11:37
  • Yes, but you're casting your object to a string, which results in [object Object], which doesn't tell anyone anything. Commented Mar 2, 2016 at 11:38

1 Answer 1

4

Yes, there is no 'concat' method for objects, it only exists in Array.prototype. Instead, you can use angular.extend method. See doc: https://docs.angularjs.org/api/ng/function/angular.extend

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.