Why is concat not working with Javascript objects?

Viewed 36

having some issues with concatenating my array to an objects array for some reason. I've already found a work around, but I'm confused as to why this is happening. When I use "concat()" is just returns an empty array.

var ListType = {

    TextField: [],
    DateField: [],
    SignatureField: []

}

function GetCursorPosition(){
    Img = document.getElementById(Ite);

    var PosX = 0;
    var PosY = 0;
    var ImgPos;
    


    ImgPos = GetImageCoordinates(Img);
    PosX = event.pageX - ImgPos[0];
    PosY = event.pageY - ImgPos[1];
    
    Coords = [PosX,PosY];
    //console.log(Coords);
    var InputType = setRadioButton();
  
    CreateList(InputType, Coords);
}


function CreateList(InputType, Coords){

    if(InputType == "Text"){
        ListType.TextField.concat(Coords);
    }
    else if(InputType == "Date"){
        ListType.DateField.concat(Coords);
    }
    else{
        ListType.SignatureField.concat(Coords);
    }
    console.log(ListType.TextField);
}

When I use the "push()" method instead I get an array of arrays which isn't what I want so I tried using "concat()" and I just get "Array []". However, if i supersede the array and just push PosX and PosY I get what I want but it seems sloppy. Plus the whole point of this project is to learn website development and javascript so I'd like to understand what I'm doing wrong. Also if you have a solution that i could implement please no JQuery, trying to learn javascript before I open that can of worms.

0 Answers
Related