Convert String to array then remove last element - Javascript Array Operation

Javascript examples for Array Operation:Array Convert

Description

Convert String to array then remove last element

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=( function() {//w ww  .j  a  v a  2  s  . c  o  m
var path = "/bar/foo/moo/";
var split = path.split("/");
var x = split.slice(0, split.length - 2).join("/") + "/";
console.log(x);
    });

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials