//基本类型与引用类型也就是栈内存还是堆内存,栈快而小,堆大而需要引用索引
//数字、字符串、数组、对象、函数的定义
var a = 27.50;
var b = 'hello world';
var c = [];
var d = {};
var e = function(){};
//数字
a.toFixed(4); //27.5000 非常好用的格式化方法
//字符串
b.substr(6); //world
b.replace('o','m'); //hellm world
b.replace(/o/ig,'m'); //hellm wmrld
b.indexOf('o'); //4
function allIndexOf(Str,str){
var a = [];
var index = Str.indexOf(str);
while(index > -1){
a.push(index);
index = Str.indexOf(str,pos + 1);
}
return a;}
allIndexOf(b,'o'); //[4,7]
//Math内置对象
function random(start,end){
var total = end - start + 1;
return Math.floor(Math.random()*total + start);
}
random(3,8); //3到8之间的随机数
Math.round(2.5); //3
Math.ceil(2.1); //3
Math.floor(2.8); //2
本文详细介绍了JavaScript中数字、字符串、数组、对象、函数的基本定义与操作方法,包括toFixed格式化、substr子串提取、replace替换字符、Math内置对象的使用等核心内容。
148

被折叠的 条评论
为什么被折叠?



