如何对一个字符串或数组进行一系列操作?

2026-04-06 11:421阅读0评论SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计216个文字,预计阅读时间需要1分钟。

如何对一个字符串或数组进行一系列操作?

plaintextgistfile1.txt一些常见操作字符串var str=hello world;// 返回所在位置document.write(str.indexOf(world));// 匹配document.write(str.match(world));// 替换document.write(str.replace(world, 二逼));

gistfile1.txt

一些常见操作 字符串 var str="hello world"; //document.write(str.indexOf("world"));//返回所在位置 //document.write(str.match("world"));//匹配 //document.write(str.replace("world","二傻"));//替换 //document.write(str.toUpperCase()); //document.write(str.toLowerCase());//大小写 //var str="hello,xixi,erya"; //var s=str.split(",");//定义分割线 //document.write(s[1]); 数组 //var a=["hello","world","d","c","b","a"]; //var b=["xixi","erya"]; //var c=a.concat(b);//合并 //document.write(c); //document.write(a.sort());//排序 //document.write(a.sort(function(a,b){ //return b-a; //}));//倒序 //b.push("keke");//追加 //document.write(b); //var a=["c","b","a"]; //document.write(a.reverse());//翻转 //document.write(Math.round(2.5));//四舍五入 //document.write(Math.random()*10);//0-1(*10)的随机数 //document.write(parseInt(Math.random()*10));//设置成整数 //document.write(Math.max(10,20,30)); document.write(Math.abs(-10));//绝对值

如何对一个字符串或数组进行一系列操作?

本文共计216个文字,预计阅读时间需要1分钟。

如何对一个字符串或数组进行一系列操作?

plaintextgistfile1.txt一些常见操作字符串var str=hello world;// 返回所在位置document.write(str.indexOf(world));// 匹配document.write(str.match(world));// 替换document.write(str.replace(world, 二逼));

gistfile1.txt

一些常见操作 字符串 var str="hello world"; //document.write(str.indexOf("world"));//返回所在位置 //document.write(str.match("world"));//匹配 //document.write(str.replace("world","二傻"));//替换 //document.write(str.toUpperCase()); //document.write(str.toLowerCase());//大小写 //var str="hello,xixi,erya"; //var s=str.split(",");//定义分割线 //document.write(s[1]); 数组 //var a=["hello","world","d","c","b","a"]; //var b=["xixi","erya"]; //var c=a.concat(b);//合并 //document.write(c); //document.write(a.sort());//排序 //document.write(a.sort(function(a,b){ //return b-a; //}));//倒序 //b.push("keke");//追加 //document.write(b); //var a=["c","b","a"]; //document.write(a.reverse());//翻转 //document.write(Math.round(2.5));//四舍五入 //document.write(Math.random()*10);//0-1(*10)的随机数 //document.write(parseInt(Math.random()*10));//设置成整数 //document.write(Math.max(10,20,30)); document.write(Math.abs(-10));//绝对值

如何对一个字符串或数组进行一系列操作?