SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Jan 2009
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Splice from multi-dimensional array?

    Splice from multi-dimensional array?

    Hi all

    I have multi-dimensional array - 3 arrays inside another array.

    I want to splice from one of the arrays and replace the removed item.

    How can I splice from a multi-dimensional array?

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    
    	<title>Splice from multi-dimensional array</title>
    	
    </head>
    
    <body>
    
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
      <script type="text/javascript">
        
        var colors_arr = new Array();
        var numbers_arr = new Array();
        var names_arr = new Array();
        var all_arr = new Array();
        //
        colors_arr.push('red','green','blue','black','yellow');
        numbers_arr.push('one','two','three','four','five');
        names_arr.push('Chris','John','Jack','Sarah','Jane');
        //
        all_arr.push(colors_arr);
        all_arr.push(numbers_arr);
        all_arr.push(names_arr);
        //
        alert(all_arr[2]);
        
        var arr = 2;
        var item = 2;
        var replace = 'Jill';
        
        all_arr.splice([arr][item],1, replace);
        
        alert(all_arr[2]);
        
        
      </script>
    </body>
    </html>

  2. #2
    SitePoint Addict
    Join Date
    Jan 2009
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think I've worked it out

    Code:
    all_arr[arr].splice(item,1, replace);


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •