What’s a way to append a value to an array?

Discussion in 'JavaScript' started by raspms, Mar 12, 2012.

  1. #1
    hello,
    can anybody explain me how to append the value of array in javascript?
    is this any function is their for that?
     
    raspms, Mar 12, 2012 IP
  2. rainborick

    rainborick Well-Known Member

    Messages:
    424
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    120
    #2
    arrayName.push(newValue);
     
    rainborick, Mar 13, 2012 IP
  3. javamazon

    javamazon Active Member

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    66
    #3
    [SIZE=+1]We can append a value to an array using one of the two methods shown below1.push() - add elements in end of the array2.unshift() - add elements in begining of the array.For example;int limit=2;string[] arrsize = new string[limit];arrsize[0] = "java";arrsize[1] = "jsp";arrsize.push("j2ee")[/SIZE]
     
    javamazon, Apr 20, 2012 IP
  4. singh1720

    singh1720 Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Sample code
    var msgArray = new Array(3);
    msgArray[0] = "Welcome to";
    msgArray[1] = "forums";
    msgArray[2] = "DigitalPoint";
    msgArray .push("Hola");
    for (var i = 0; i < msgArray.length; i++) {
    alert(msgArray );
    };
     
    singh1720, Apr 27, 2012 IP