Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Javascript Adding Array Elements

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 481
    Comment on it

    In Javascript you can add one or more element into an array with the hepl of push() method and it will return new length of an array .
    Syntax ->
    arrayname.push(element1, element2 ,.........elementN )
    Parameters ->
    elementN- > New Element/s will be added to the end of the array .
    Return->It will return new lenght of an array after adding the element into an array .

    Example ->
    1) Adding New elements into an array ->

    var names = [ 'Mukesh ' , ' Ravi ' , 'Abhishek ' ,  ' Ayush ' ] ; <br>
    var arrnames = names.push( 'Ishan ' , ' Medha ') ; <br>
    document.write( names ) ; //output -> Mukesh   Ravi  Abhishek   Ayush   Ishan   Medha <br>
     document.write( arrnames ) ; //output -> It will return the length of new array "6".
    

    2) Merging of two arrays

    var fname = [ 'Mukesh ' , ' Ravi ' , 'Abhishek ' ,  ' Ayush ' ] ; <br>
    var lname = [ ' Tomar ' , ' Badoni ' , ' Kumar ' ,  ' Gupta ' ] ; <br>
    Array.prototype.push.apply(fname , lname) ;<br>
    console.log(fname) // output ->  'Mukesh ' , ' Ravi ' , 'Abhishek ' ,  ' Ayush '  ' Tomar ' , ' Badoni ' , ' Kumar ' ,  ' Gupta ' 
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: