JS字符串截取,字符串分割,拼接等

2019-08-14  本文已影响0人  i_木木木木木
   let str = 'hello world'
   console.log(str1.substring(3,7))      ////lo w
   console.log(str1.substr(3,7))      ////lo worl
   console.log(str1.slice(3,7))      ////lo w
   let arr = [];
   let str="jpg|bmp|gif|ico|png";
   arr=str.split("|");
   console.log(arr);    ////["jpg", "bmp", "gif", "ico", "png"]
  let arr = ["jpg", "bmp", "gif", "ico", "png"];
  let str = arr.join('-');
  console.log(str);    //// "jpg-bmp-gif-ico-png"
     let str = "hello world javascript!";
     let index1 =str.indexOf("java");    
     let index2 =str.indexOf("jAva");
     console.log(index1)    //12
     console.log(index2)    //-1
     let  src="hello world javascript!";
     let index1 =str.indexOf("java");    
     let index2 =str.indexOf("jAva");

     console.log(index1)    //12
     console.log(index2)    //-1
上一篇下一篇

猜你喜欢

热点阅读